How to implement method chaining?

后端 未结 4 1939
死守一世寂寞
死守一世寂寞 2021-02-08 20:27

In C# how does one implement the ability to chain methods in one\'s custom classes so one can write something like this:

myclass.DoSomething().DosomethingElse(x)         


        
4条回答
  •  遥遥无期
    2021-02-08 21:24

    For a mutable class, something like

    class MyClass
    {
        public MyClass DoSomething()
        {
           ....
           return this;
        }
    }
    

提交回复
热议问题