20 Sep 2017

what is static variable in C Sharp with example


Static variable does not create in non static class.

Static variable declare always global level and class level 
but we can't declare static variable on method level.

syntex:-

If you want to make the int B=15 static then out put is 11.

Static variable created by on time memory allocated but memory in will be value override.

As a before 11 then after override 12. 

Example of Static variable:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace what_is_static_variable
{
   class Program
    {
        static int a = 10;
        public  void Show()
        {
             a++;
            Console.WriteLine(a);
        }
    }
    class Devesh
    {
       public static void Main(string[] args)
        {
            Program aa = new Program();
            aa.Show();
            Console.ReadKey();
        }
    }

}
Output:-

No comments:
Write comments

Contact Form

Name

Email *

Message *

© 2014 Rock Programmer . Designed by Bloggertheme9
Powered by Rock Programmer.