Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The significance of <> in C#

Tags:

c#

.net

class

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(); 

What does the <> signify? And why is there a . (dot) in front of it?

like image 698
Frederik Brinck Jensen Avatar asked Dec 30 '12 14:12

Frederik Brinck Jensen


People also ask

What does <> mean in C language?

<> in some languages means "does not equal". But in c, the operator is != . Also note the difference between logical AND ( && ) and bitwise AND ( & ). You should use the logical operators for multiple criteria in a conditional statement.

What does <> do in code?

It means "the developer probably came from BASIC and thought using a less well-known alias for a well-known operator is fine". :p.

How do you use not equal to in C?

The equal-to operator ( == ) returns true if both operands have the same value; otherwise, it returns false . The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .


1 Answers

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.

like image 140
Damien_The_Unbeliever Avatar answered Sep 19 '22 14:09

Damien_The_Unbeliever