gpt4 book ai didi

c# - 在 C# 中从数组中查找和删除项目

转载 作者:行者123 更新时间:2023-12-04 16:27:53 28 4
gpt4 key购买 nike

我有一个字符串数组。我需要从该数组中删除一些项目。但我不知道需要删除的项目的索引。

我的数组是: string[] arr= {"","a","b","","c","","d","","e","f","",""}。

我需要删除“”项目。即删除“”后我的结果应该是
arr={"a","b","c","d","e","f"}

我怎样才能做到这一点?

最佳答案

  string[] arr = {" ", "a", "b", " ", "c", " ", "d", " ", "e", "f", " ", " "};
arr = arr.Where(s => s != " ").ToArray();

关于c# - 在 C# 中从数组中查找和删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9375585/

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