Advertisement
Fhernd

ImplicitlyTypedLocals.cs

Nov 11th, 2017
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. class ImplicitlyTypedLocals
  2. {
  3.     static void Main()
  4.     {
  5.         string[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" };
  6.  
  7.         // If a query produces a sequence of anonymous types,
  8.         // then use var in the foreach statement to access the properties.
  9.         var upperLowerWords =
  10.              from w in words
  11.              select new { Upper = w.ToUpper(), Lower = w.ToLower() };
  12.  
  13.         // Execute the query
  14.         foreach (var ul in upperLowerWords)
  15.         {
  16.             Console.WriteLine("Uppercase: {0}, Lowercase: {1}", ul.Upper, ul.Lower);
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement