---
title: "Concept of Class in C#"  
description: "This is the place where the designing or structure or blueprint of the program with variable is store.  C# provides the platform to create variable of"  
author: "Jonas Stuart"  
published: 2016-09-17  
updated: 2018-03-16  
canonical: https://www.mindstick.com/blog/11206/concept-of-class-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 3 minutes  

---

# Concept of Class in C#

This is the place where the designing or [structure](https://www.mindstick.com/articles/23258/choose-your-business-structure-wisely) or blueprint of the program with variable is store. C# provides the [platform](https://www.mindstick.com/articles/13080/wikipedia-the-most-powerful-advertising-platform-of-the-digital-age) to create variable of different types , methods and events. It can be used to declare variable, [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server), event etc along with [datatype](https://www.mindstick.com/forum/32/stored-procedure-return-datatype) and access specifier.\

**How to Design Class ?**

For designing of class we need to use Class keyword.

< Access specifier > Class Demo {

}

**What is an object for the class?**

We can define object of the class , same as variable is created for the datatype.

Syntax // classtest a = new classtest();

**Why to create object of the class?**

By creating an object for the class, a memory is allocated according to the length of [variables](https://www.mindstick.com/articles/715/php-variables) or .We can create many object of the class.

But we make Static class by using [Static Keyword](https://www.mindstick.com/forum/105398/what-is-the-static-keyword) before class. Then we can’t create object for that class because by using static keyword [instances](https://answers.mindstick.com/qa/92508/how-can-you-hide-the-sql-server-instances) for the memory is already allocated in the memory. It can’t be inherited.

**Example :**

```
Static Class demo{Static Void fun1(){Console.WriteLine(“New Version”);}}Class program { Demo D1 = new demo(); // error  will come.}We don’t need to create any object . directly use the
name of the class for any function or variable.For example Class program { Demo.fun1()}Main(string[] args)
```

**Points to be remember:** All the member of Static class must be Static.

Default Access Specifier for the class is Internal and for the class member default is Private.

If you are beginner then you must thinking that " Shall we passs [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) while initiating the object".

Answer of this question is "Yes".

**Question may arrise how ?**

For this answer you must have [knowledge](https://www.mindstick.com/forum/156160/what-is-google-knowledge-graph) about Constructor and Destructors.

For the object there is a [default constructor](https://www.mindstick.com/forum/34531/default-constructor) used to initialize memory. We can create constructor also it should have the same name as of class.

**syntax :**

```
   class Line           
        {                    public int Loan;   // Length of a line                   public Line(int a) // constructor                    {                   Console.WriteLine("Object is
being created");                   Loan +=a;                   }
```

for the above class we need to pass the parameter while initalising the object for the class. Such contructor is called parameterized constructors.

Destructors is just reverse of Contructor. In simple word it is used for releasing the memory after the cexecution of the class. we can create Destructor also it

should have the same name as of class with prefix of special charactor "~".

**Syntax**

```
      ~Line() //destructor      {         Console.WriteLine("Object is being deleted");      }
```

When we don't specify, assess specifier for the Class then by default it is "Public" and default access specifier for its member is "Private".

When we assigned any member as Static and if we can to create many object for the class then also only one memory is allotted for that member

**For example :**

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace ConsoleApplication1{    class StaticV    {        public
static int num = 0;        public void
count()        {            num++;        }        public void
print()        {           
Console.WriteLine("Variable num : {0}", num);        }    }    class
StaticTester    {        static void
Main(string[] args)        {            StaticV
s1 = new StaticV();            StaticV
s2 = new StaticV();           
s1.count();           
s2.count();           
s1.print();           
s2.print();           
Console.ReadKey();        }    }}
```

**This blog is to provide some basic knowledge about the class and it is also helpful to provide clear answer for the doubts related to c#.**

---

Original Source: https://www.mindstick.com/blog/11206/concept-of-class-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
