Charl Potgieter Charl Potgieter - 1 year ago 119
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]

Answer Source

or just

var result = test.Where(x => x.IndexOf(" P", StringComparison.OrdinalIgnoreCase) > 0);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download