C# is an object oriented programming. Objects are related to real life scenario. It is taken from real world. Class is the general thing and object is the specialization of general thing. Object is instance of class that is created dynamically.
- Object class is the ultimate base class of every type.
- Object is also a keyword that is a class for the predefined type System.Object in the .net framework.
- Instances of classes are created by using the new operator.
- Member functions of the class are accessed through an object of the class by using the dot (.) operator.
Class is a like a blueprint it defines the data and behaviour of type. An object is basically a block of memory that has been allocated and configured according to the blueprint. A class can have many objects according program need. Objects are also called instances, and they can be stored in either a named variable or in an array or collection.
In an object-oriented language such as C-Sharp, classes are reference types. To use member function and variable of class. You need to create an object of the class.
Details obj=new Details(); //Create Object
An object is used to interact with each other to pass a massage and respond to the received message.
A variable of a class object holds a reference to the address of the object on the managed heap. All the objects of a class share the same copy of the member functions but they maintain a separate copy of the member variables in memory. If a second object of the same type is assigned to the first object, then both variables refer to the object at same address.
Let’s see an example of Object
In the preceding program, there are two classes Details and Program.
Details class contain two member variables, a constructor method and normal method. Another class Program contain an object of Details class and calling Details class member function and variable by objects.