I have an enumerated type that I would like to define the >
, <
, >=
, and <=
operators for. I know that these operators are implictly created on the basis of the enumerated type (as per the documentation) but I would like to explictly define these operators (for clarity, for control, to know how to do it, etc...)
I was hoping I could do something like:
public enum SizeType
{
Small = 0,
Medium = 1,
Large = 2,
ExtraLarge = 3
}
public SizeType operator >(SizeType x, SizeType y)
{
}
But this doesn't seem to work ("unexpected token") ... is this possible? It seems like it should be since there are implictly defined operators. Any suggestions?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…