Object initializer syntax: anonymous types vs actual types #2665
Unanswered
TonyValenti
asked this question in
Language Ideas
Replies: 2 comments
-
@TonyValenti I feel like you shouldn't because in the first example you define a new property which makes more sense to me whereas in the second example you initialize an existing property so I don't know, it might be confusing to some people but then maybe it's just me. Edit: Rephrased. |
Beta Was this translation helpful? Give feedback.
0 replies
-
That reminds me a little bit on #2616 int Capacity = 100;
var list = new List<int> ()
{
Capacity
}; This compiles and adds the value 100 to the list. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Right now I an create an anonymous type like so:
When I create a regular type, I can't do that though and have to specify the property name even when it matches a variable name. I should be able to do:
Beta Was this translation helpful? Give feedback.
All reactions