CompareTo() is very easy to understand but I just seem to have a blind spot about it.
int result = instance.CompareTo(obj);
Result | Meaning |
Less than zero | instance is less than obj |
Zero | instance is equal to obj |
Greater than zero | instance is greater than obj |
For this | Use this |
if (instance < obj) | if (instance.CompareTo(obj) < 0) |
if (instance <= obj) | if (instance.CompareTo(obj) <= 0) |
if (instance == obj) | if (instance.CompareTo(obj) == 0) |
if (instance > obj) | if (instance.CompareTo(obj) > 0) |
if (instance >= obj) | if (instance.CompareTo(obj) >= 0) |
No comments:
Post a Comment