Answer the question
In order to leave comments, you need to log in
How to limit expansion?
Good morning.
There is an extension for all data types
public static Int32 ToInt32(this Object line)
{
return Convert.ToInt32(line);
}
Answer the question
In order to leave comments, you need to log in
This cannot be done, unfortunately.
I propose to make several similar methods in one class, one for each required type:
public class NumericExtensions
{
public static Int32 ToInt32(this Double line)
{
return (Int32)line;
}
public static Int32 ToInt32(this float line)
{
return (Int32)line;
}
public static Int32 ToInt32(this String line)
{
var res;
int.TryParse(line, out res);
return res;
}
// ... для каждого нужного типа
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question