C# (C Sharp) - Object Oriented Programming

C# (C Sharp) - Object Oriented Programming

  • C# provides full support for object-oriented programming including encapsulation, inheritance, and polymorphism. 
  • Object-oriented programming (OOP) is the core ingredient of the .NET framework. OOP is so important that, before embarking on the road to .NET, you must understand its basic principles and terminology to write even a simple program. The fundamental idea behind OOP is to combine into a single unit both data and the methods that operate on that data; such units are called an object. All OOP languages provide mechanisms that help you implement the object-oriented model. 
  • Encapsulation means that a group of related properties, methods, and other members are treated as a single unit or object. 
  • Inheritance describes the ability to create new classes based on an existing class. 
  • Polymorphism means that you can have multiple classes that can be used interchangeably, even though each class implements the same properties or methods in different ways.

Classes and Objects 

The terms class and object are sometimes used interchangeably, but in fact, classes describe the type of objects, while objects are usable instances of classes. So, the act of creating an object is called instantiation. Using the blueprint analogy, a class is a blueprint, and an object is a building made from that blueprint. 

To define a class in C#:

class SampleClass 


Object, in C#, is an instance of a class that is created dynamically. Object is also a keyword that is an alias for the predefined type System. Object in the .NET framework. 

Object Creation Example:

Product obj = new Product 

ID = 21, 

Price = 200, 

Category = "XY", 

Name = "SKR", 


"oops concepts in c#"

"oops concepts in c# with examples"

"c# oops interview questions"