Reputation: 85
I have list of string 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.
Upvotes: 2
Views: 2082
Reputation: 229
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); }
Upvotes: 0
Reputation: 882
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();
Upvotes: 1
Reputation: 8595
stringList.Where(s => s.StartsWith("04"))
or
stringList.Where(s => s.StartsWith("04")).ToList()
if you need a list
Upvotes: 9