设置一个包含零个元素的列表-
List<string> myList = new List<string>();
现在检查列表是否为空或为空-
Console.WriteLine(myList == null);
在上面,返回“ False”,即列表不为空-列表为空。
让我们看完整的代码-
using System;
using System.Collections.Generic;
using System.Linq;
public class Demo {
public static void Main() {
List<string> myList = new List<string>();
//返回false,即一个空列表(不是空列表)
Console.WriteLine(myList == null);
}
}输出结果
False