Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created September 26, 2013 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/6721454 to your computer and use it in GitHub Desktop.
Save Fhernd/6721454 to your computer and use it in GitHub Desktop.
Demostración de var en reconocimiento de tipos anónimos en C#.
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