//use it like: string s=4.5; double d = s.ToDouble();
public static double ToDouble(this object source)
{
double val = 0;
if (source != null)
{
string str = Convert.ToString(source);
if (! string.IsNullOrEmpty(str))
{
double.TryParse(str, out val);
}
}
return val;
}
Monday, January 30, 2012
Best Extension Methods: Convert To Double
Below extension method converts a value/object to double and if its not convertible then returns 0.0;
Share This!
Labels:
C#.NET,
Extension Methods
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment