---
title: "Static method and variables in c#"  
description: "Static method and variables in c#"  
author: "Anonymous User"  
published: 2015-11-25  
updated: 2015-11-25  
canonical: https://www.mindstick.com/forum/33639/static-method-and-variables-in-c-sharp  
category: "c#"  
tags: ["c#", ".net"]  
reading_time: 1 minute  

---

# Static method and variables in c#

I want to know what is [Static method](https://www.mindstick.com/blog/440/creating-static-methods-in-c-sharp) and [variables](https://www.mindstick.com/articles/715/php-variables) in c# and how to use please help me.

## Replies

### Reply by Anonymous User

Whenever you write a function or declare a variable, it doesn’t create instance in a memory until you create object of class. But if you declare any function or variable with [static](https://www.mindstick.com/articles/12098/the-static-keyword-the-static-methods) modifier, it directly create instance in a memory and acts globally. The static modifier doesn’t reference with any object.

It is very easy to create static modifier with variables, functions and classes. Just put static keyword before the return data type of [method](https://www.mindstick.com/forum/166/webservice-method).

```
using System;namespace Static_variable_and_method{    class StaticNumber    {        // Create static variable        public static string Name;        //Create static method        public static void GetName()        {            Console.WriteLine("Your name is {0}{1}", "Ms.", Name);            Console.ReadLine();        }    }    class Program    {        static void Main(string[] args)        {            Console.Write("Enter Your Name\t");            StaticNumber.Name = Convert.ToString(Console.ReadLine());            StaticNumber.GetName();        }    }}
```

![Static method and variables in c#](https://www.mindstick.com/mindstickforums/1c2d9dd0-e9d7-47e0-a151-459cf2bf7d06/images/3f12ce9c-e52f-40cb-a2ad-1576b711628c.png)


---

Original Source: https://www.mindstick.com/forum/33639/static-method-and-variables-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
