How to C # turn a variable name into a property name of an anonymous object?

When you create a new anonymous object using the following syntax:

string name = "Foo";
var myObject = new { name };

You get an object with a property named 'name':

myObject.name == "Foo"; //true

What method does C # use to retrieve a variable name?

+3
source share
2 answers

Basically, this expression is equivalent to

new { name = name }

since an explicit property name is not provided.

# name. (, , ). . ( ). - .

+5

: " ?" ( ), , . . , , , , , . , , .

" ?" " , ". , , , ( , , ); .

+5
source

Source: https://habr.com/ru/post/1719192/


All Articles