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 - C# Tutorial
From the course: C# Best Practices for Developers
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Method overloading5m 16s
-
(Locked)
Unit testing without parameters4m 5s
-
(Locked)
Unit testing with parameters2m 54s
-
(Locked)
Method chaining4m 7s
-
(Locked)
Constants vs. read-only fields5m 28s
-
(Locked)
Using properties correctly2m 11s
-
(Locked)
Using properties demo4m 29s
-
(Locked)
Auto-implemented properties1m 33s
-
(Locked)
Auto-implemented properties demo5m 13s
-
(Locked)
-
-
-