Skip to content

Why 'await' causing compiler error when that in an interpolated string? #39149

@Connect-a

Description

@Connect-a

The following code cannot be compiled:

        private static async Task Main()
        {
            // compiler error CS0103 : The name 'await' does not exist in the current context
            var z = $"{await (Task.FromResult(string.Empty))}";

            // allowed
            var a = await Task.FromResult(string.Empty);
            var b = await (Task.FromResult(string.Empty));
            var c = $"{await Task.FromResult(string.Empty)}";

            Console.ReadLine();
        }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions