A class or struct definition is like a blueprint
that specifies what the type can do. An object is a block of memory that has
been allocated and configured according to the blueprint. A program may create
many objects of the same class. , A class is a data structure that combines
state (fields) and actions (methods and other function members) in a single
unit. And Object is an entity that has state and behavior. Here, state
means data and behavior mean functionality. The object is an instance of a class.
All the members of the class can be accessed through the object.
Example of Class and Object in C#
using System;
namespace ClassAndObjectExampleNameSpace
{
public class ExampleClass //class
{
public void Method_PrintSomething() // method
{
Console.WriteLine("this is simple method of class ExampleClass");
}
public static void Main(string[] args)
{
ExampleClass obj = new ExampleClass(); // create the object of class
//call the method of class using its object
obj.Method_PrintSomething();
Console.ReadLine();
}
}
}
|