1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public struct SizeType
{
private int InternalValue { get; set; }
public static readonly int Small = 0;
public static readonly int Medium = 1;
public static readonly int Large = 2;
public static readonly int ExtraLarge = 3;
public override bool Equals(object obj)
{
SizeType otherObj = (SizeType)obj;
return otherObj.InternalValue.Equals(this.InternalValue);
}
public static bool operator >(SizeType left, SizeType right)
{
return (left.InternalValue > right.InternalValue);
}
public static implicit operator SizeType(int otherType)
{
return new SizeType
{
InternalValue = otherType
};
}
}
public class test11
{
void myTest()
{
SizeType smallSize = SizeType.Small;
SizeType largeType = SizeType.Large;
if (smallSize > largeType)
{
Console.WriteLine("small is greater than large");
}
}
} |
Partager