gpt4 book ai didi

c# - 使用 StartsWith 将值与字符串数组进行比较

转载 作者:可可西里 更新时间:2023-11-01 09:00:29 32 4
gpt4 key购买 nike

我有一个数组:

string[] exceptions = new string[] { "one", two", "one_1", "three" };

..我想说:

var result = from c in myCollection
where not c.Property[3].Value.StartWith(exceptions)
select c;

所以我希望过滤 myCollection 以仅显示那些 Property[3].Value StartWith 异常数组中的一个值。我知道 StartsWith 不接受集合,所以我不确定这是否可以通过 LINQ 实现。

这在 LINQ 中可能吗?!还是我试图将我的问题硬塞进 LINQ 解决方案中?

编辑:我应该说,Contains 不是一个选项,因为我只想排除其属性以异常字符串开头的元素。

最佳答案

var result =  myCollection.Where(c =>  
exceptions.All(e =>
!c.Property[3].Value.StartsWith(e));

关于c# - 使用 StartsWith 将值与字符串数组进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8240861/

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