C# 中的空列表

csharpprogrammingserver side programming更新于 2025/8/11 23:52:17

C# 中存在空列表。要检查列表是否为空,请根据空值字面量进行检查。 像这样设置一个空值 −

List<string> myList = null;

现在,要检查是否为空,请使用相等运算符 −

myList == null;

下面是一个例子 −

示例

using System;
using System.Collections.Generic;
using System.Linq;
public class Demo {
   public static void Main() {
      List<string> myList = null;
      // 检查是否为空
      Console.WriteLine(myList == null);
   }
}

输出

True

相关文章