Try to change static value in different instance : Class Instance « Class « C# / CSharp Tutorial






using System;

class MyClass
{
   int nonStaticVariable;
   static int staticVariable;

   public void SetVars(int v1, int v2) 
   {
      nonStaticVariable = v1;
      staticVariable = v2;
   }

   public void Display()
   {
      Console.WriteLine("nonStaticVariable= {1}, staticVariable= {2}", nonStaticVariable, staticVariable);
   }
}

class MainClass
{
   static void Main()
   {
      MyClass d1 = new MyClass(), d2 = new MyClass();

      d1.SetVars(2, 4);    
      d1.Display();

      d2.SetVars(15, 17);  
      d2.Display();

   }                       
}








7.2.Class Instance
7.2.1.Invoke a method in a class
7.2.2.Instance Class Members
7.2.3.Try to change static value in different instance
7.2.4.public member method
7.2.5.Creating an array of objects.
7.2.6.Call GetType and ToString on object instance