C# program to show how static data member works in a class

Category > CSHARP || Published on : Tuesday, November 3, 2020 || Views: 515 || static data member works in a class


Here Pawan Kumar will explain how to to show how static data member works in a class

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication9
{
    class A
    {
        static int n;
        public void Get(int x)
        {
            n = x;
        }
        public void Show()
        {
            Console.WriteLine("n=" + n);
        }

    }
    class sta_tic
    {
        static void Main()
        {
            A a = new A();
            a.Get(99);
            a.Show();
            A b = new A();
            b.Get(200);
            b.Show();
            a.Show();
            Console.ReadLine();
         }
    }
}