c# 具有特定“where”“is null”的 lambda 表达式

问题描述 投票:0回答:1

有人可以告诉我如何创建一个 C# lambda 表达式 以获得以下结果:

我想获取所有值不以“B”开头的行。因此 ID 为 1、3、4、5 和 6 的行需要出现在结果中。包括具有 NULL 值的那个。

身份证 价值
1 A01
2 B01
3
4
5 A02
6 A02
7 B02

.Where(x => !x.Value.StartsWith("B"))
没有给出具有 NULL 值的行

提前致谢。

c# lambda null where-clause
1个回答
0
投票

怎么样

list.Where(x => string.IsNullOrEmpty(x.Value) || !x.Value.StartsWith("B"));

© www.soinside.com 2019 - 2024. All rights reserved.