Using Static Variables - CSharp Custom Type

CSharp examples for Custom Type:static

Description

Using Static Variables

Demo Code

class point/*from   w  w  w.j ava2  s . c  o m*/
{
   public int x;
   public int y;
}
class line
{
   static public point origin= new point();
   public point ending = new point();
}
class MainClass
{
   public static void Main()
   {
      line line1 = new line();
      line line2 = new line();
      // set line origin
      line.origin.x = 1;
      line.origin.y = 2;
      // set line1's ending values
      line1.ending.x = 3;
      line1.ending.y = 4;
      // set line2's ending values
      line2.ending.x = 7;
      line2.ending.y = 8;
      // print the values...
      System.Console.WriteLine("Line 1 start: ({0},{1})", line.origin.x, line.origin.y);
      System.Console.WriteLine("line 1 end:   ({0},{1})", line1.ending.x, line1.ending.y);
      System.Console.WriteLine("Line 2 start: ({0},{1})", line.origin.x, line.origin.y);
      System.Console.WriteLine("line 2 end:   ({0},{1})\n", line2.ending.x, line2.ending.y);
      // change value of line2's starting point
      line.origin.x = 939;
      line.origin.y = 747;
      // and the values again...
      System.Console.WriteLine("Line 1 start: ({0},{1})", line.origin.x, line.origin.y);
      System.Console.WriteLine("line 1 end:   ({0},{1})", line1.ending.x, line1.ending.y);
      System.Console.WriteLine("Line 2 start: ({0},{1})", line.origin.x, line.origin.y);
      System.Console.WriteLine("line 2 end:   ({0},{1})", line2.ending.x, line2.ending.y);
   }
}

Result


Related Tutorials