Search code examples
c#.netsyntaxasync-awaitnotation

What does this notation involving angle brackets mean?


I'm reading Async in C# 5.0, and the section on the compiler transform contains this snippet:

public Task<int> AlexsMethod()
{
    <AlexsMethod>d__0 stateMachine = new <AlexsMethod>d__0();
    stateMachine.<>4__this = this;
    stateMachine.<>t__builder = AsyncTaskMethodBuilder<int>.Create();
    stateMachine.<>1__state = -1;
    stateMachine.<>t__builder.Start<<AlexsMethod>d__0>(ref stateMachine);
    return stateMachine.<>t__builder.Task;
}

There are two pieces of notation that are new to me. The first is <AlexsMethod>d__0. The second is stateMachine.<>4__this. Neither works when I try them myself, so I suspect it's for use by the compiler only. But I'm having trouble searching for more information on what is intended by this notation.


Solution

  • Unlike the brackets marking generics (e.g. Task<int>), they don't have special meaning. They're just what the compiler generates - identifiers that are valid in IL, but not in C#.