ภาพรวม
ใช้ operator default เพื่อดึงค่าเริ่มต้นของชนิดข้อมูล สำหรับ bool ค่าเริ่มต้นคือ false
รูปแบบการใช้งาน
bool a = default(bool); // false // หรือ C# 7.1+: bool b = default; // type inference
ตัวอย่างโค้ดเต็ม
using System;
public class Demo
{
public static void Main()
{
bool a = default(bool);
Console.WriteLine("Default for bool type = " + a);
}
}
ผลลัพธ์
Default for bool type = False
ตารางค่าเริ่มต้นของชนิดพื้นฐาน
| ชนิด | Default Value |
|---|---|
| bool | false |
| byte, short, int, long | 0 |
| float, double | 0.0 |
| decimal | 0.0M |
| char | '\0' (null char) |
| reference types (string, class, array, delegate) | null |
| struct | struct ที่ทุก field เป็น default |