---
title: "Static Class in C#."  
description: "Such type of class which is marked by static keyword is known as static class. All the members of static class must be static. We cannot declare non-s"  
author: "Anonymous User"  
published: 2011-05-05  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/153/static-class-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Static Class in C#.

Such type of class which is marked by [static keyword](https://www.mindstick.com/forum/105398/what-is-the-static-keyword) is [known as](https://answers.mindstick.com/qa/35703/ricky-ponting-is-also-known-as-what) static class. All the members of static class must be static. We cannot declare non-static members inside static class. We can access members of static class by using [Class name](https://www.mindstick.com/forum/12871/how-to-get-class-name) followed by access [operator](https://www.mindstick.com/blog/144/union-intersection-and-except-operator-in-sql-server) dot (.) followed by [method name](https://www.mindstick.com/forum/33583/selector-creation-with-method-name-and-parameter). One thing important that we cannot instantiate static class means to say we cannot create object of static class by using new keyword.\

##### The following list provides the main feature of a static class

\

1) Contains only static members except for constants.

2) Cannot create [objects](https://www.mindstick.com/forum/145447/what-are-objects) of static class.

3) Is [sealed class](https://www.mindstick.com/forum/33880/difference-between-abstract-class-and-sealed-class).

4) Can not contain [instance](https://www.mindstick.com/forum/1739/object-reference-is-not-set-to-an-instance-of-an-object-error-in-my-code) constructor or [non static](https://www.mindstick.com/interview/2733/can-you-access-non-static-variable-in-static-context) constructor.

##### Creating static class

For creating static class we can use static keyword at the beginning of class.

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace PropertyDemo{    //use static keyword to create a static class.    static class Program    {        static Program()        {            Console.WriteLine("This is a static constructor.");        }        static string message;        static void disp()        {            Console.WriteLine(message);        }        public static void Main(string[] args)        {            Program.message = "Hello John...";  //Accessing static variables.            Program.disp();      //Accessing static methods.            Console.ReadLine();        }    }}
```

##### Output:

This is a static constructor.\
Hello John...

---

Original Source: https://www.mindstick.com/blog/153/static-class-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
