c# - 如何使用where条件

标签 c# linq dynamic

我们可以在 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/

相关文章:

c# - 按范围对数据进行分组以制作直方图

c# - NHibernate 如何查询 IList<string> 属性?

java - Java 中的可变长度(动态)数组

t-sql - 条件/可选 where 语句

c# - 在计算模拟器中分析 Azure

c# - 新创建的 GTK# 项目出现错误

c# - 优雅的解决方案 - 使用 Linq-To-SQL 批量删除和重新添加相关的子列表

objective-c - Objective-C 中的收集能力有什么意义?

c# - c# 中的可绑定(bind)对象?

c# - 如何从 OpenFileDialog 获取文件路径并将其传递给 PDFReader? (C#)