Possible Duplicate:
Static extension methods
So I know that Extension methods are for object instances only as in doing
public static string stringBig(this string inString) {
return inString.ToUpper();
}
Only works for an instance of string
However I am trying to make something that function like Double.TryParse so that I don’t have to do
Double myDouble = someOtherDouble.DoubleParseDifferent("4.324802348203498");
I’d like to be able to do something like
Double myDouble = Double.DoubleParseDifferent(someRandomString);
Now I know that I can’t actually do this so what would be some alternative methods or ways I could approach this.
The only possible alternative way for implementing
TryParseI can think of (since what you’re asking for is not possible) would be creating a normal static method, but returning a nullable.That way you would not need a output parameter like the normal
TryParse…If
!result.HasValue, then the parse was not successful. Otherwise, just read theresult.Valueproperty to get the parsed result.