Select with Anonymous Types: prints uppercase and lowercase versions of each string in an input array

image_pdfimage_print
   
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass {
    public static void Main() {

        string[] words = { "Abc", "aBc", "AAA" };

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

        foreach (var ul in upperLowerWords) {
            Console.WriteLine("Uppercase: {0}, Lowercase: {1}", ul.Upper, ul.Lower);
        }
    }
}

    


This entry was posted in LINQ. Bookmark the permalink.