C# 中的空列表


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;
      // checking for null
      Console.WriteLine(myList == null);
   }
}

輸出

True

更新於:2020 年 6 月 22 日

2K+ 瀏覽次數

啟動您的 職業

完成課程,獲得認證

開始
廣告
© . All rights reserved.