
A class is like a blueprint of specific object. In the real world, every object has some color, shape and functionalities. For example, the luxury car Ferrari. Ferrari is an object of the luxury car type. The luxury car is a class that specify certain characteristic like speed, color, shape, interior etc. So any company that makes a car that meet those requirements is an object of the luxury car type. For example, every single car of BMW, lamborghini, cadillac are an object of the class called 'Luxury Car'. Here, 'Luxury Car' is a class and every single physical car is an object of the luxury car class. Likewise, in object-oriented programming, a class defines certain properties, fields, events, method etc. A class defines the kinds of data and the functionality their objects will have. A class enables you to create your own custom types by grouping together variables of other types, methods and events. In C#, a class can be defined by using the class keyword.
Note : Every class must contain a won constructor, same name of the class.
Every Thing is class, C# Has Two type of class’s
- User Defined
- Pre Defined
String is also a class, it’s Pre Defined class.
Ex: User Defined :
Pre Defined :
We can see string is also Class. It is Sealed class.
C# is based on the C and C++ programming language. Hence, the C# programming language has in-built support for classes and objects. A class is nothing but an encapsulation of properties and methods that are used to represent a real-time entity.