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.

有帮助吗?

解决方案

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#.

其他提示

When you use lambda expression, lambda expression is a anonymous method. But compiler need to give it a name, so these methods are generated by compiler, it is not readable for human.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top