Is there an equivalent C # syntax for defining a built-in anonymous C structure?

Greetings Overflowers,

I know that in C we can define a struct inline with a variable declaration so that the struct type is specific to that variable. This is instead of defining only the type and then declaring the variable with that type of structure. Is this possible in C #?

Thank!

+5
source share
2 answers

This is not possible in C #, however you can define an instance of an anonymous type as follows:

var x = new { SomeField = 1, SomeOtherField = "Two" }; 

This will be virtually the same, giving you an instance of a type that is specific to this variable and cannot be used outside the scope of variables.

+14

: , .

+1

All Articles