---
title: "Static Member"  
description: "A C# class can contain both static and non-static members.When we declare a member with the help of the keyword static, it becomes astatic member. A s"  
author: "Uttam Misra"  
published: 2010-10-07  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/14/static-member  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Static Member

A C# class can contain both static and non-static members.When we declare a member with the help of the [keyword](https://www.mindstick.com/forum/33572/sql-inner-join-keyword) static, it becomes astatic member. A static member belongs to the class rather than to the objectsof the class. Hence static members are also [known as](https://answers.mindstick.com/qa/35703/ricky-ponting-is-also-known-as-what) class members andnon-static members are knows as [instance](https://www.mindstick.com/forum/1739/object-reference-is-not-set-to-an-instance-of-an-object-error-in-my-code) members.\

Static Field:

Static field can be [declared as](https://www.mindstick.com/interview/2711/what-if-the-main-method-is-declared-as-private) follows by using the keywordstatic.

```
Class myclass{Public static int x;Public static int y=20;}
```

When we declare a static field inside a class, it can beinitialized with a value .All un-initialized static fields automatically getinitialized to their [default values](https://www.mindstick.com/blog/10881/default-values) when the class is loaded first time.

The C# provides a special type of constructor knows asstatic constructor to initialize the static data member when the class isloaded at first time. Other static member [functions](https://www.mindstick.com/forum/160140/explain-the-role-of-functions-as-a-service-faas-in-serverless-computing), static constructor cannotaccess non-static members directly.

The name of a static constructor must be the name of theclass and even they don't have any return type. The static constructor cannottake any arguments. That means there is only [one form](https://answers.mindstick.com/qa/93702/how-does-one-form-a-connection-between-his-inner-self-and-the-materialistic-world) of static constructor,without any arguments. It is not possible to overload a static constructor.

Static Member [Function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server):

Inside a C# class, member functions can be declared asstatic. But a static member function can access only other static members. Theycan [access non](https://www.mindstick.com/interview/2733/can-you-access-non-static-variable-in-static-context)-static members only through an instance of class.

##### Example:

```
Class myclass{Private static int x=20;Private static int y=40;Public static void method(){Console.WriteLine(“{0},{1}”,x,y);}}Class myclint{Public static void main(){Myclass.method();}}
```

---

Original Source: https://www.mindstick.com/blog/14/static-member

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
