如何从C#中的空字符串列表中删除空字符串?
首先,设置一个以空字符串为元素的列表。
List<string> myList = new List<string>() {
" ",
" ",
" "
};现在让我们使用索引删除一个空元素。
myList.RemoveAt(0);
示例
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
List<string> myList = new List<string>() {
" ",
" ",
" "
};
Console.Write("Initial list with empty strings...\n");
foreach (string list in myList) {
Console.WriteLine(list);
}
Console.Write("Removing an empty element from the list...\n");
myList.RemoveAt(0);
foreach (string list in myList) {
Console.WriteLine(list);
}
Console.WriteLine("Empty List after deleting an empty element is shown above...");
}
}输出结果
Initial list with empty strings... Removing an empty element from the list... Empty List after deleting an empty element is shown above...
热门推荐
10 同学朋友吃饭祝福语简短
11 祝朋友祝福语简短好看
12 婚礼美句简短祝福语
13 给母校送花祝福语简短
14 离别对同事祝福语简短
15 给哥哥高考祝福语简短
16 祝福语简短创意闺蜜
17 别人转岗的祝福语简短
18 给老师祝福语简短元旦