سؤال

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?

هل كانت مفيدة؟

المحلول

Try using this

long id = Convert.ToInt64(ObjectToConvert)

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top