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