Creating Properties - CSharp Custom Type

CSharp examples for Custom Type:Property

Description

Creating Properties

Demo Code

class point/*w ww.ja v a  2s  .  co  m*/
{
   int my_X;  // my_X is private
   int my_Y;  // my_Y is private
   public int x
   {
      get
      {
         return my_X;
      }
      set
      {
         my_X = value;
      }
   }
   public int y
   {
      get
      {
         return my_Y;
      }
      set
      {
         my_Y = value;
      }
   }
}
class MyApp
{
   public static void Main()
   {
      point starting = new point();
      point ending   = new point();
      starting.x = 1;
      starting.y = 4;
      ending.x = 10;
      ending.y = 11;
      System.Console.WriteLine("Point 1: ({0},{1})", starting.x, starting.y);
      System.Console.WriteLine("Point 2: ({0},{1})", ending.x, ending.y);
   }
}

Result


Related Tutorials