I understand the "CompareTo compares the instance and the value(represented in my code by amountA - instance and amountB-value) and it could return 1, -1 or 0 depending on what we have for the instance and value.
Could anyone explain me why it returns 1,-1 or 0? Although I was able to use it, I'd like to understand this method a bit better.
Thank you!
See bellow my C# code//
if (Math.Round(amountA, 2).CompareTo(Math.Round(amountB, 2)) == 0)
{
return ("Plan " + planA.Name + " costs " + amountA) + " " + ("Plan " + planB.Name + " costs " + amountB) + " " + message3;
}
else if (amountA.CompareTo(amountB) > 0)
{
return ("Plan " + planA.Name + " costs " + amountA) + " " + ("Plan " + planB.Name + " costs " + amountB) + " " + message1;
}
else if (amountA.CompareTo(amountB) < 0)
{
return ("Plan " + planA.Name + " costs " + amountA) + " " + ("Plan " + planB.Name + " costs " + amountB) + " " + message2;
}
return "";
}