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:
Note : System.Linq namespace is must for all linq queries used in your .net page.
Happy Coding...
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
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: .net2.0, .net3.5, collections.system.linq, linq, namespace, query, string
Post a Comment