I am trying to convert string to integer from a object's property, where i am facing lot of problems.
1st Method
public class test
{
public string Class { get; set; }
}
//test.Class value is 150.0
var i = Convert.ToInt32(test.Class);
It is saying error that Input String is not in a correct format
2nd Method
int i = 0;
Int32.TryParse(test.Class, out i);
The value of the above code is always zero
3rd Method
int j = 0;
Int32.TryParse(test.Class, NumberStyles.Number, null, out j);
Here i am getting the value as 150 correctly but as I am using null for IFormatProvider Will there be any problem with this?
Which is the proper method for converting string to integer with these cases?
"150.0"which is a floating point value to an integer?