I'm having a weird problem, trying to take a string from a string array and convert it to an integer. Take a look at this code snippet:
string date = "21/07/2010 13:50";
var date1 = date.Split(' ')[0];
string[] dateArray = date1.Split('/');
string s = "21";
string t1 = dateArray[0];
bool e = string.Compare(s, t1) == 0; //TRUE
int good = Convert.ToInt32(s); //WORKING!
int bad = Convert.ToInt32(t1); //Format exception - Input string was not in a correct format.
Can someone please explain why the conversion with s works, while with t1 fails?
t1equals?t1will be "2010 13:50" when you try to parse it.String#Compareprobably isn't doing what you think it should be doing.Format ExceptionWORKING!because there's no actuals1change yourstos1.