The significance of <> in C#

前端 未结 3 1044
礼貌的吻别
礼貌的吻别 2020-12-05 00:25

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__DisplayCl         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 00:36

    You're looking at some decompiled code - specifically, something that was generated by the compiler.

    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.

    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.

提交回复
热议问题