LINQ StartsWith

By Riley K

Equivalent of Like opertor in LINQ

Normally in SQL we use LIKE Operator to get results starting with certain character

In LINQ there is no LIKE method instead its Equivalent in to use StartsWith Method

For example I got a list of these strings

List<string> lstNames = new List<string>();
            lstNames.Add("Riley Keller");

Now i want to display the results starting with 'M', Here is how you query it

var result = lstNames.Where(name => name.StartsWith("M"));

            foreach (var s in result)
Here is the output

LINQ StartsWith  (2427 Views)