Let's say I have an integer that I need to convert to a string (I might be displaying the value to the user by means of a TextBox, for example.
Should I prefer .ToString()
or Convert.ToString()
. They both do the same thing (don't they?).
int someValue = 4;
// You can do this
txtSomeValue.Text = someValue.ToString();
// Or this...
txtSomeValue.Text = Convert.ToString(someValue);
Assuming that there is no runtime difference between the two, then my reasons come down to aesthetics and consistency. Recently I have been favouring Convert.ToString()
as to me it says "hey, I want the value of this thing as a string". However I know that this is not strictly true...