C# 中的空列表
设置一个有 0 个元素的列表 -
List<string> myList = new List<string>();
现在检查列表是空的还是 null -
Console.WriteLine(myList == null);
上面返回 “False”,即列表不为 null - 列表为空。
让我们看看完整的代码 -
范例
using System;
using System.Collections.Generic;
using System.Linq;
public class Demo {
public static void Main() {
List<string> myList = new List<string>();
// returns false i.e. an empty list (not a null list)
Console.WriteLine(myList == null);
}
}输出
False
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP