เมธอด Boolean.Equals(Boolean) ใน C# ใช้สำหรับคืนค่าที่บ่งชี้ว่าอินสแตนซ์นี้เท่ากับออบเจ็กต์ Boolean ที่ระบุหรือไม่
ไวยากรณ์
ไวยากรณ์มีดังนี้:
public bool Equals (bool ob);
พารามิเตอร์ ob คือค่า Boolean ที่ต้องการเปรียบเทียบกับอินสแตนซ์นี้
ตัวอย่าง
ตัวอย่างการใช้งานเมธอด Boolean.Equals(Boolean):
using System;
public class Demo {
public static void Main(){
bool b1 = false;
bool b2 = true;
bool res = b1.Equals(b2);
if (res == true)
Console.Write("b1 equal to b2");
else
Console.Write("b1 not equal to b2");
}
}
ผลลัพธ์
โค้ดจะแสดงผลดังนี้:
b1 not equal to b2