超载功能的简短方法?

Mic*_*ino 0 c# overloading

为什么要以更短的方式做到这一点?我想到了类似的东西void DoSth(int i) : DoSth(i, this);.

class Foo
{

   void DoSth(int i)
   {
      DoSth(i, this);
   }

   static void DoSth(int i, Foo foo)
   {
      // do sth
   }

}
Run Code Online (Sandbox Code Playgroud)

编辑:忘static了第二个功能

Bur*_*dar 6

如果您使用的是C#6,则可以在类似方法的成员上使用表达式主体:

class Foo
{
    public DoSth(int i) => DoSth(i, this); 

    static void DoSth(int i, Foo foo)
    {
          // do sth
    }
}
Run Code Online (Sandbox Code Playgroud)