C#: Inherit from Boolean?
问题 (how) can I Inherit from Boolean? (Or make my class comparable to Boolean with '=' Operator) class MyClass : Boolean { public MyClass() { this = true; } } class Program { public Program() { MyClass myClass = new MyClass(); if(myClass == true) //do something... else //do something else... } } 回答1: Simple example: public class MyClass { private bool isTrue = true; public static bool operator ==(MyClass a, bool b) { if (a == null) { return false; } return a.isTrue == b; } public static bool