As i am new to C# programming language i am a little confused about C# syntax.
A method which can get two values to compare those two values can be written as a.compareTo(b) instead of compareTo(a,b) How is it possible?
Assuming that compareTo returning an int the variable a is chained to int and gets compared! How?
Thank you in advance.
In C#, the
intkeyword actually represents a structure of typeSystem.Int32. This type has several methods available on it, one of those beingCompareTo(Int32)as you have seen.CompareTofor anInt32object takes in an integer value, compares that value to itself and returns the result, very simply like this:The
thiskeyword refers to the current instance of the Type that this method belongs to, in your casea.The documentation for
Int32and its methods can be found here.