Information générale
Catégorie:
Code, syntaxe and commandes
>>I thought they originally didn't want 'var'. Doesn't it go against the C# design principle of strong typing?
>>
>
>Not at all. It's still strongly-typed. It's just that now the compiler and Intellisense is smart enough to infer the type based on the return type. When you use var you aren't saying "I don't won't know it's type until later", but instead, "Hey, compiler, figure out the correct type for me". "var" was actually necessary to allow for anonymous types, which was necessary for LINQ. It's kind of interesting if you look at the language elements added to 3.5 how many of them were required in order to get LINQ working.
The whole language is still fascinating to me. I know I will be discovering tidbits about it for years to come.
Do you have a suggestion for the next thread in my little C# series? How about generics?
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement