From the course: Advanced C# Programming Concepts

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

What are delegates?

What are delegates?

- [Instructor] In this chapter, we will discuss C# delegates and how they can help improve the modularity of your code. You can think of delegates as being simply placeholders for functions that will be called at some point. So the same way you can declare a variable that holds an integer or a string, you can declare a variable that will hold a reference to a function. So this gives you a way to change the function that will be called at runtime. So instead of calling a single hard-coded function, you can swap out the function you want to call while the program is running based upon the program's needs at that moment. So in other words, delegates give you a way to logically separate different parts of your application from each other without having to know in advance what all those modules are going to be. In fact, this even has a name. This approach is usually referred to as the strategy design pattern where you can change how the program operates behind the scenes as needed. Even…

Contents