c# - 将列表中的空字符串更改为零

标签 c# linq

我有一个列表:

IEnumerable<string> fields = row.ItemArray.Select(field => field.ToString());

其中一些值是空字符串。我想将所有空字符串更改为“0”。我可以使用 1 行 linq 命令来执行此操作吗?

最佳答案

如果 ItemArray 不包含字符串,请不要忘记 field 上的 ToString()

IEnumerable<string> fields = row.ItemArray.Select(field => 
    string.IsNullOrWhitespace(field.ToString()) ? "0" : field.ToString());

关于c# - 将列表中的空字符串更改为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33134223/

相关文章:

c# - 使用 linq 查找导航点列表所需的距离

c# - 仅在使用 LINQ 时引用需要错误

c# - 使用 Linq Dynamic 进行分组

c# - ParallelEnumerable.Range 与 Enumerable.Range.AsParallel 对比?

c# - 如何测量连接到 Citrix 场的用户数量

c# - 具有委托(delegate)类型的通用方法

c# - 如何从 KeyValuePair 列表中进行选择?

c# - Visual Studio 2010扩展中如何获取文本光标的绝对位置

c# - 如何在项目开始时执行迁移

javascript - $ 不是 b.$scope.SaveUser 的函数