Charl Potgieter Charl Potgieter - 2 months ago 10x
C# Question

Use second element of a split string in LINQ where query

Is the following possible: Retrieve all last name that starts with a p using LINQ. But the first name and last name is one word separated by a space.
Example would be Jonh Peter. Luke Sam, Rock Papers,Lee P

I tried the following:

var result = test.Where(x => x.Owner.Split(' ')[1]


or just

var result = test.Where(x => x.IndexOf(" P", StringComparison.OrdinalIgnoreCase) > 0);