« Home | SQL in .net Using LINQ » | Querying the DataTable in .Net » | Converting DataView into DataTable » | Deleting TFS Project »

Using LINQ in String Collections

By using LINQ we can query the String Collections.

How ? Find it below..

Assume that you have a collection of strings.

####Code Begin####

String [] Names = {"naren","mandhir","vishal","vinod","rajesh","mani","pandey"};

Lets find the Names whose length is greater than 5, using LINQ.

IEnumerable Name = from n in Names where n.lenght  > 5 select n;

Thats it, lets print the names.

foreach(string strName in Name)
{
Console.WriteLine("{0}", name);
}

####Code Ends####

And the output will be:

mandhir
vishal
rajesh
pandey

Note : System.Linq namespace is must for all linq queries used in your .net page.

Happy Coding...                 

Labels: , , , , , ,

Post a Comment

Translate

About me

Narayanan
Senior Software Engineer
Microsoft Certified Professional Developer
MCPD

Chat

Visitors