Question

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?

Was it helpful?

Solution

Try using this

long id = Convert.ToInt64(ObjectToConvert)

and might be prone to error unlike TryParse() in the datatype

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top