gpt4 book ai didi

c# - 如何使用where条件

转载 作者:太空狗 更新时间:2023-10-29 22:55:55 26 4
gpt4 key购买 nike

我们可以在 linq 查询中动态附加 where 条件吗?

例如:

class Result
{
string v1;
string v2;
string v3;
}

List<Result> result = (from r in results select r);


//i want to do something like the following....

if(conditionA)
{
result = result appened (or v1 = xxx)
}
else if(conditionB)
{
result = result appened (or v2 = xxx)
}
else if(conditionC)
{
result = result appened (or v3 == xxx)
}

有人知道如何处理 Linq 中的条件吗????

最佳答案

如果你想动态构建它,你可以使用 PredicateBuilder

关于c# - 如何使用where条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2330722/

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