From the course: C# Best Practices for Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Method chaining

Method chaining - C# Tutorial

From the course: C# Best Practices for Developers

Start my 1-month free trial

Method chaining

- [Instructor] Something that you always want to keep in mind when you're creating your methods, or just coding in general, is to avoid code duplication. And when we're dealing with methods, one way to do this is to by having the majority of the code that is duplicated in one method, and have other methods called the first, that has the majority of the work. So for example, we have two book actor methods here. We can minimize what's in here on line 47 through 49, and have the majority of the work on our second book actor method. This is called Method Chaining. That is, when one method calls another method to get most of the work done. Let's go ahead and modify this to demonstrate what I'm referring to. In this method, I can just return the results of calling our second book actor method. And what I'll do, is just pass in an empty string. And so I'll modify our second method to handle what needs to get done when it has a date, or if it's an empty string. So after our first line here…

Contents