Madhuri Lad Madhuri Lad - 1 month ago 20
C# Question

In clause in lambda expression

var Charts = chartGroup
.Descendants("charts")
.Elements("chart")
.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
in
clause in SQL) for
Attribute("id").Value
for array of strings:

like:

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


how to achieve this?

Answer

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

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