ตั้งค่ารายการที่มีองค์ประกอบเป็นศูนย์ -
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>();
// returns false i.e. an empty list (not a null list)
Console.WriteLine(myList == null);
}
} ผลลัพธ์
False