I have list of s开发者_如何学Gotring and there are number of string in the list. Each string in the list start with number.
List<String> stringList=new List<String>();
stringList.Add("01Pramod");
stringList.Add("02Prakash");
stringList.Add("03Rakhi");
stringList.Add("04Test");
stringList.Add("04Test1");
stringList.Add("04Test2");
I want a Linq query that will return me list of string that starts with 04.
stringList.Where(s => s.StartsWith("04"))
or
stringList.Where(s => s.StartsWith("04")).ToList()
if you need a list
var result = stringList.Where(i => i.StartsWith("04"));
Here are the possible solution for it:
// Lambda
stringList.FindAll(o => o.StartsWith("04"));
// LINQ
(from i in stringList
where i.StartsWith("04")
select i).ToList();
I guess this will be easy to understand and its in proper format
var ss=from string g in stringList
where g.Substring(0,2)=="04"
select g;
foreach(string str in ss) { Console.WriteLine(str); }
精彩评论