Generic type that extends bool

How can I make my generic type "extend" boolean?
c#
class MyClass<T> where T : bool {
}
c#
class MyClass<T> where T : bool {
}
4 Replies
Angius
Angius3mo ago
That generic parameter would be quite useless, wouldn't it? System.Boolean is a sealed record, so you can't extend it The only possible route is composition, basically
class MyClass
{
private bool _value;
}
class MyClass
{
private bool _value;
}
and maybe explicit cast operators And other overloads that would make it compatible with bool
oke
oke3mo ago
im pretty sure that all base types are sealed to avoid program obfuscation (complications) things like strings, bools, ints, etc
wasabi
wasabi3mo ago
They're sealed because they're not classes. They're value types in the CIL, and you cannot inherit from value types. But they're also primitives.
sexysexysamthorpe
why do you want to do this
Want results from more Discord servers?
Add your server
More Posts