我学习C#和陷入一片code,我不明白。我希望你能clearify对我来说。
I'm studying C# and caught a piece of code that I don't understand. I was hoping that you could clearify it for me.
CreateCustomerTask.<>c__DisplayClass0 cDisplayClass0 =
new CreateCustomerTask.<>c__DisplayClass0();
什么的&LT;&GT;
意味着什么?为什么有一个。
(点)在它的前面?
What does the <>
signify? And why is there a .
(dot) in front of it?
您正在寻找一些反编译code - 确切地说,是由编译器生成的东西
You're looking at some decompiled code - specifically, something that was generated by the compiler.
编译器使用&LT;&GT;
(这是一个实现细节),因为,虽然它是有效的CLR标识符做起了这样的文字,它不是在C#有效 - 所以它保证该名称不会在C#code任何名称冲突
The compiler uses <>
(this is an implementation detail) because, whilst it's valid for a CLR identifier to start with such characters, it's not valid in C# - so it's guaranteed that the name will not conflict with any names in the C# code.
为什么的编译器生成此code变化 - 它可以是实施拉姆达的,或迭代器或异步块,可能还有一些其他的原因,也
why the compiler has generated this code varies - it can be the implementation of a lambda, or an iterator or async block, and possibly some other reasons also.
和,希望你的问题的另一部分还回答了 - 有一个
在它前面的通常的原因 - 以独立的名称空间的部分,或更可能在这种情况下,从封闭类名称的嵌套类的名称区分开来。
And, hopefully the other part of your question is also answered - there's a .
in front of it for the usual reasons - to separate namespace portions, or more likely in this case, to separate the name of a nested class from the name of the enclosing class.