Reputation: 1045
I had a variable of type object and I wanted to convert it to int in advance.?
prev code
val = Math.Max(((int)DatabaseHelper.ExecuteScalerCommand(query)), numbering.StartValue);
Now I need to convert it to type long. I try to use long.tryparse()
long t = 0;
long.TryParse(DatabaseHelper.ExecuteScalerCommand(query).ToString(), out t);
var val = Math.Max(t, numbering.StartValue);
is there a better way to handle this problem?
Upvotes: 0
Views: 185
Reputation: 2992
Try using this
long id = Convert.ToInt64(ObjectToConvert)
and might be prone to error unlike TryParse() in the datatype
Upvotes: 1