Object oriented programming with C#
Classes: Class is a C# construct to model real-world objects into classes
Exa:
class Employee
{
private string _name;
private char _gender;
private string _qualification;
private uint _salary;
}
Access Modifiers
- Public:Accessible to the members of the containing class as well as non-members of the class
- Private:Accessible only to the members of the containing class
- Protected:Accessible to the containing class or types derived from the containing class
Constructors: Special method of a class that is called every time an instance of the class is created
Exa:
Employee()
{
qualification = “Graduate”;
}
Destructor: Special method to perform cleanup operations
Syntax:
{
body of destructor
}
Note:
- Methods can be overloaded on the basis of varying number of parameters or different data types.
- Namespace consists of a group of related classes
- Inheritance is the process of acquiring features of an existing class.
- The class based on which the new class is created is called base class or parent class and the class that is created is called derived, sub or child class.
- The keyword base is used to access members of the base class from inside a derived class.
- The override keyword is used to modify a method, property or an indexer.
- The new modifier is used to explicitly hide a member that is inherited from the base class.
- Abstract Classes are classes that contain at least one abstract member (method without implementation).
Abstract class cannot be instantiated. - Overriding a method is to change the implementation of the method in the derived class.
- The virtual keyword is used to modify the declaration of a method.
- Explicit Interface Implementation is used to specify which interface a member function is implementing in case of a name ambiguity.