Using Linq to find a value in comma separated value in a List

c#, linq, list

Solution

If you just want a boolean:

var isPresent = listOfRows.Any(r => r.Code.Split(",").Any(s => (---your condition---)));

If you want rows with Code property value matching your condition:

var rows = listOfRows.Where(r => r.Code.Split(",").Any(s => (---your condition---)));

If you only want Code property values:

var values = listOfRows.Select(r => r.Code.Split(",")).Where(s => (---your condition---));

Problem

I have a File Class and each file has List of Rows. Each row has Code which has comma seperated values. I need to find if a particular value exists in the comma seperated data. ``` public class File { public List<Row> Rows { get; set; } } public class Row { public string Code{ get; set; } } ``` Here code has comma sperated values like abc, def, ghi || xyz, ghj, klm I need to pick the Row which has abc as code out of the list of rows i have in the file using Linq

Original source