1
public class Person
{
    public string Name { get; set; }
}

List<Person> listOfPerson=new List<Person>();
listOfPerson.Add(new Person(){Name="Pramod"});
listOfPerson.Add(new Person(){Name="Prashant"});
listOfPerson.Add(new Person(){Name="Sachin"});
listOfPerson.Add(new Person(){Name="Yuvraj"});
listOfPerson.Add(new Person(){Name="Virat"});

I want a LINQ Solution which will return list of object whose Name property starts with "pra"

2 Answers 2

9
var results = listOfPerson.Where(
    p => p.Name.StartsWith("pra", StringComparison.CurrentCultureIgnoreCase));

foreach(Person p in results)
{
    ...
}
Sign up to request clarification or add additional context in comments.

Comments

1

Thomas's solution uses the LINQ extension methods, this uses the full LINQ query syntax.

var query = from x in listOfPerson 
            where x.Name.StartsWith("pra")
            select x;

foreach(var p in query)
{
    ...
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.