How to implement method chaining?

后端 未结 4 1955
死守一世寂寞
死守一世寂寞 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:20

    Your methods should return this or a reference to another (possibly new) object depending on exactly what you want to acheive

提交回复
热议问题