I learn something new everyday about C# and came across this construct. I am not 100% sure what it does, so can someone please explain it:
new { Name = "John"}
This was used where a string was expected as an argument to a method call.
Thanks
I learn something new everyday about C# and came across this construct. I am not 100% sure what it does, so can someone please explain it:
new { Name = "John"}
This was used where a string was expected as an argument to a method call.
Thanks
It's an object initializer for an anonymous class. It constructs an object with a single property, Name, with value "John." Since you have no way to refer to the object, you would use it right away, as in a LINQ statement or as a parameter as you mentioned.
See also this answer.
Its a new anonymous type with the property Name
set to the string "John"
.
Well, it looks to me like its creating an anonymous type with one property (Name, of type string).
But saying that it's used where a string was expected has me a little confused.