From the course: Nail Your C# Interview

Unlock the full course today

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

Explore the polymorphism built into C#

Explore the polymorphism built into C# - C# Tutorial

From the course: Nail Your C# Interview

Explore the polymorphism built into C#

- [Instructor] Polymorphism is the ability for an object or function to take many forms. Depending on the context and situation the form may be different, making your code more flexible and reducing complexity. C# supports runtime polymorphism and compile time polymorphism. Let's explore how this functionality is built into C#. Here we have the List class. We can click into it with Command + click, and see its source code. In the List class, we implement a few interfaces. An interface is a set of method signatures for to be implemented functionality. It's kind of like a specification for a set of behavior without implementation. So like an abstract class, an interface cannot be instantiated. If we click into the IEnumerable class, we'll see it requires a GetEnumerator method by those that implement it. These interfaces can also be used as data types. With the List constructor, it takes in any data type that…

Contents