Madhuri Lad Madhuri Lad - 11 months ago 102
C# Question

In clause in lambda expression

var Charts = chartGroup
.Where(x => x.Attribute("id").Value == chartId.ToString())
.Select(x => x.Attribute("name").Value).ToList();

Here I want to use an "in-clause"" (like the
clause in SQL) for
for array of strings:


Where(x => x.Attribute("id").Value in ("1","2")
Where(x => x.Attribute("id").Value` in charIds[]

how to achieve this?

Answer Source

If you have a set of values in an array, then you can use:

.Where(x => charids.Contains(x.Attribute("id").Value)