Example : C# 3.0 new features

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;namespace Example.cSharp3Dot0
{
class Program
{

static void Main(string[] args)
{
List Languages = new List { “C#”, “VB”, “VC++” }; // —-> Collection Initializer

var languageQuery = //—-> Implicitly typed local variables
from one in Languages
where one == “VC++”
select new { one }; //—-> Anonymous types.
foreach (var name in languageQuery)
{
Console.WriteLine(“Its” + name.one);
Console.WriteLine(“Its” + name.one.ToString().getFirstTwoCharacters());
Console.ReadLine();
}
}
}

public static class myClass
{
public static string getFirstTwoCharacters(this System.String st) // —-> Extension methods
{
return st.Substring(0, 2);
}

}
}

Leave a Reply