Anonymous Types

Anonymous types allow you to create the intermediate results without writing classes.

 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] names = { "Java", "C#", "Javascript" };

        var intermediate = from n in names
                           select new
                           {
                               item1 = n,
                               item2 = n.Replace("a", "").Replace("e", "").Replace("i", "")
                               .Replace("o", "").Replace("u", "")
                           };

        IEnumerable<string> query = from item in intermediate
                                    where item.item1.Length > 2
                                    select item.item2;
        foreach(string s in query){
           Console.WriteLine(s);
        }
    }
}
  

The output:


Jv
Jvscrpt
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.