Replies: 11 comments
-
The older array initializer has always been target typed. You can only use it in a variable initializer, and it uses the type of the variable. (note that you cannot use the array initializer syntax with var). The other two initializers are not target typed. They are inferring the array type from the elements specified. The first example has no elements. The second example has a single value which must be understood as int, and is then incompatible with byte[]. |
Beta Was this translation helpful? Give feedback.
-
@mattwar Thanks for the explanation, just an opinion though, it was nicer if I didn't have to ask and it's just worked but then I guess no language is perfect. :) |
Beta Was this translation helpful? Give feedback.
-
Never thought I'd say it but perfection is subjective. :-) |
Beta Was this translation helpful? Give feedback.
-
We seemed to be adding a lot of target typed features into the language now, so maybe there is hope. |
Beta Was this translation helpful? Give feedback.
-
@jnm2 I guess so but what I really meant is I wish the transition between one syntax to another for the "same" thing was smoother or better so I thought to bring this up 😉 @mattwar Thanks! 😄 |
Beta Was this translation helpful? Give feedback.
-
How about this: var table = byte[]; //Array.Empty<byte>();
byte[] table = []; //Array.Empty<byte>(); |
Beta Was this translation helpful? Give feedback.
-
@dsaf C# is not JS 😄 var arr = [];
for(...)
arr.push(something) is not applicable here. |
Beta Was this translation helpful? Give feedback.
-
@Pzixel |
Beta Was this translation helpful? Give feedback.
-
@dsaf so what? it's 145 from 5051938sloc = 1 occurence per 35k lines of code. There are 202 |
Beta Was this translation helpful? Give feedback.
-
@dsaf Might be more useful to create an issue about it than a comment though, I mean, if you really want it. :) |
Beta Was this translation helpful? Give feedback.
-
Literals for Dictionaries( and Lists and their types) is being discussed in #414 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In the following cases the compiler complains that it can't resolve the type based on the current information and I'm wondering what's the reason for it? it seems a bit odd that the shorthand works but the more explicit syntax doesn't.
Case 1:
Case 2:
However, it works when we use the array initializer syntax:
Anyway, just thought to point it out.
Beta Was this translation helpful? Give feedback.
All reactions