Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending string with Extension Methods (C# 3.0)?

I know I can extend the string class like so:

public static class EMClass
{
   public static int ToInt32Ext(this string s)
   {
      return Int32.Parse(s);
   }
   public static int ToInt32Static(string s)
   {
      return Int32.Parse(s);
   }
}

And use it like this:

string x = "12";
x.ToInt32Ext()

But how can I make it to where I can use it like this:

int x = string.ToInt32("15");
like image 948
Bob Dylan Avatar asked Nov 30 '22 11:11

Bob Dylan


1 Answers

I don't think you can do "static" extension methods.

like image 180
Andy Gaskell Avatar answered Dec 14 '22 00:12

Andy Gaskell