x.Attri-6ren">
gpt4 book ai didi

c# - lambda 表达式中的子句

转载 作者:太空狗 更新时间:2023-10-29 18:03:59 25 4
gpt4 key购买 nike

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

在这里,我想为字符串数组的 Attribute("id").Value 使用“in-clause”(就像 SQL 中的 in 子句) :

喜欢:

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

如何实现?

最佳答案

如果数组中有一组值,则可以使用:

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

关于c# - lambda 表达式中的子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20212162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com