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);
etc…
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Chaining is a good solution to produce new instance from existing instances:
Usage:
You can also use this pattern to modify an existing instance, but this is generally not recommended:
Usage: