Pages

Thursday, 8 October 2015

Inheritence in C#

 

What is inheritance?


Inheritance represents the relationship between two classes where one type derives functionality from a second type and then extends it by adding new methods, properties, events, fields and constants.

C# support two types of inheritance:
·         Implementation inheritance
·         Interface inheritance



What is implementation and interface inheritance?


When a class (type) is derived from another class(type) such that it inherits all the members of the base type it is Implementation Inheritance.
When a type (class or a struct) inherits only the signatures of the functions from another type it is Interface Inheritance.
In general Classes can be derived from another class, hence support Implementation inheritance. At the same time Classes can also be derived from one or more interfaces. Hence they support Interface inheritance.




How do you prevent a class from being inherited?
In VB.NET you use the NotInheritable modifier to prevent programmers from using the class as a base class. In C#, use the sealed keyword.

No comments:

Post a Comment

Get or Update fields on form using JavaScript in Dynamics 365 v9

After Microsoft released v9.0 of Microsoft Dynamics 365, Xrm.page became deprecated that it have been replaced by ExecutionContext.getFor...