Extension Methods in C# | Extension Methods in CSharp with Real-time Examples

preview_player
Показать описание
Extension Methods in C# | Extension Methods in CSharp with Real-time Examples
In this video, I am going to discuss Extension Methods in C# with Examples. At the end of this video, you will understand what exactly Extension Methods are and when and how to use these extension methods in C# with Examples?

What are Extension Methods in C#?
It is a new feature that has been added in C# 3.0 which allows us to add new methods into a class without editing the source code of the class i.e. if a class consists of a set of members in it and in the future if you want to add new methods into the class, you can add those methods without making any changes to the source code of the class.

Extension methods can be used as an approach to extending the functionality of a class in the future if the source code of the class is not available or we don’t have any permission in making changes to the class.

Before extension methods, inheritance is an approach that is used for extending the functionality of a class i.e. if we want to add any new members to an existing class without making a modification to the class, we will define a child class to that existing class and then we add new members in the child class.
In the case of an extension method, we will extend the functionality of an existing class. In this case, we will create a new class and by using that new class we will extend the functionality of an existing class.

Both these approaches can be used for extending the functionalities of an existing class whereas, in the case of inheritance, we call the methods defined in the old and new classes by using the object of the new class whereas, in the case of extension methods, we call the old and new methods by using the object of the old class.

Note: Sometimes inheritance is not possible. That means if the class is declared using the sealed modifier, then we cannot create a derived class from the sealed. But we can extend the functionality of sealed class using the Extension Method.

#extensionmethods #csharpextensionmethods #csharpextensionmethodsexamples #extensionmethodsexamples #csharptutorials #dotnettutorials #csharp #dotnet

Extension Methods
Extension Methods C#
Extension Methods in C#
Extension Methods in C# with Examples
Extension Methods CSharp
Extension Methods in CSharp
Extension Methods in CSharp with Examples
C# Extension Methods
C# Extension Methods Examples
CSharp Extension Methods
CSharp Extension Methods Examples
What are Extension Methods in C#?
What are Extension Methods in CSharp?
C# Extension Methods Real-Time Examples
CSharp Extension Methods Real-Time Examples
Extension Methods in C# with Real-time Examples
Рекомендации по теме
Комментарии
Автор

In this video, I am going to discuss Extension Methods in C# with Examples. Please watch the video and give your valuable feedback.

DotNetTutorials