มีรายการว่างใน C # ในการตรวจสอบว่ารายการเป็นโมฆะหรือไม่ ให้ตรวจสอบกับค่า null ตามตัวอักษร ตั้งค่า null แบบนี้ -
List<string> myList = null;
ตอนนี้ เพื่อตรวจสอบค่า 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