Advertisement
Guest User

Point

a guest
Dec 25th, 2014
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2.  
  3. class Point
  4. {
  5.     //constructor
  6.     public Point(int xCoord, int yCoord)
  7.     {
  8.         this.X = xCoord;
  9.         this.Y = yCoord;
  10.     }
  11.     //fields
  12.     private int xCoord;
  13.     private int yCoord;
  14.  
  15.     //properties
  16.     public int X
  17.     {
  18.         get
  19.         {
  20.             return this.xCoord;
  21.         }
  22.         set
  23.         {
  24.             if ((xCoord < 0) || (xCoord > 100))
  25.             {
  26.                 throw new ArgumentOutOfRangeException("The value must be in the range [0..100]");
  27.             }
  28.             else
  29.             {
  30.                 this.xCoord = value;
  31.             }
  32.         }
  33.     }
  34.     public int Y
  35.     {
  36.         get
  37.         {
  38.             return this.yCoord;
  39.         }
  40.         set
  41.         {
  42.             if ((yCoord < 0) || (yCoord > 100))
  43.             {
  44.                 throw new ArgumentOutOfRangeException("The value must be in the range [0..100]");
  45.             }
  46.             else
  47.             {
  48.                 this.yCoord = value;
  49.             }
  50.         }
  51.     }
  52. }
  53. class Program
  54. {
  55.     public static void Main()
  56.     {
  57.         Point p1 = new Point(1000, -1000);
  58.  
  59.         Console.WriteLine(p1.X);
  60.         Console.WriteLine(p1.Y);
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement