Created
September 26, 2013 22:26
-
-
Save Fhernd/6721454 to your computer and use it in GitHub Desktop.
Demostración de var en reconocimiento de tipos anónimos en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImplicitlyTypedLocals | |
{ | |
static void Main() | |
{ | |
string[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" }; | |
// If a query produces a sequence of anonymous types, | |
// then use var in the foreach statement to access the properties. | |
var upperLowerWords = | |
from w in words | |
select new { Upper = w.ToUpper(), Lower = w.ToLower() }; | |
// Execute the query | |
foreach (var ul in upperLowerWords) | |
{ | |
Console.WriteLine("Uppercase: {0}, Lowercase: {1}", ul.Upper, ul.Lower); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment