Class :
A user-defined data structure that groups properties and methods. Class doesn’t occupies memory.
Object :
Object is a Building and the class is a blueprint. Instance of Class is called object.
An object is created in memory using keyword “new”.Property :
Attribute of object is called properties. Eg1:- A car has color as property
Encapsulation :
Encapsulation is a process of binding the data members and member functions into a single unit.
Abstraction :
Abstraction is a process of and displaying the essential features and hiding the implementation details.
Inheritance :
Reusability of Base class members in Derived Class is called Inheritance.
Polymorphism :
When a message can be processed in different ways is called polymorphism. Polymorphism means many forms.
Polymorphism is of two types:
- Compile time polymorphism (Early Binding)/Overloading
- Runtime polymorphism (LateBinding)/Overriding
-
Operator Overloading :
using System; // A three-dimensional coordinate class.
class ThreeD {
int x, y, z; // 3-D coordinates
public ThreeD() { x = y = z = 0; }
public ThreeD(int i, int j, int k) { x = i; y = j; z = k; }
public static ThreeD operator +(ThreeD op1, ThreeD op2) // Overload binary +.
{
ThreeD result = new ThreeD();
/* This adds together the coordinates of the two points and returns the result. */
result.x = op1.x + op2.x; // These are integer additions
result.y = op1.y + op2.y; // and the + retains its original
result.z = op1.z + op2.z; // meaning relative to them.
return result;
} // Show X, Y, Z coordinates.
public void show()
{
Console.WriteLine(x + ", " + y + ", " + z);
}
}
public class ThreeDDemo {
public static void Main() {
ThreeD a = new ThreeD(1, 2, 3); ThreeD b = new ThreeD(10, 10, 10); ThreeD c = new ThreeD();
c = a + b; c.show(); c = a + b + c;
c.show(); }
}
00:27 |
Category:
C# Concepts
|
0
comments
Comments (0)