What is the difference (both in terms of correctness and performance) between doing the following comparisons.
int a = 100;
string b = "100";
if (a == Convert.ToInt16(b))
//Do something
if (a.ToString() == b)
//Do Something
If I have a string value that is always an int (say for storing an int in a hidden field on a webpage) I have always compared both values as integers because that is what the data is representing, but I would like a more technical reason.
Comparing strings somewhat works for equality and inequality, but not for other comparisons.
For instance,
a < Convert.ToInt16(b)is not the same thing asa.ToString() < b.For that reason alone, I personally always prefer comparing numbers instead of strings.