Linq Example 2 : Example 2- Anonymous Types

5:03 AM
In this example we will use Anonymous Types in Linq..

Let's See the Example:

string[] strWords =  { "oNe", "TwO", "tHrEe" };

            var words =
                from w in strWords
                select new { Upper = w.ToUpper(), Lower = w.ToLower() };

            foreach (var t in words)
                Console.WriteLine(t.Lower + "  " + t.Upper);

We are converting each string in strWords to its Lower and Upper Case and storing it to a new datatype with Two Properties :

1 . Lower
2.  Upper

It's Just like a structure and with each string in strWords we are creating a object of this structure containing the Lower and Upper Case of the respected strWords.


one  ONE
two  TWO
three  THREE


Post a Comment