Advertisement
tuturox

Untitled

Sep 2nd, 2022 (edited)
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1.  class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             Point _point1 = new Point("1point", 10, 10);
  6.             Point _point2 = new Point(20, 30);
  7.             Point _point3 = new Point("3point");
  8.  
  9.             Console.WriteLine(_point1.GetCoordsAndName); //result: (1point, 10, 10)
  10.             Console.WriteLine(_point2.GetCoordsAndName); //result: (, 20, 30)
  11.             Console.WriteLine(_point3.GetCoordsAndName); //result: (3point, 100, 300)
  12.  
  13.  
  14.         }
  15.  
  16.         public class Point
  17.         {
  18.  
  19.             private int x, y;
  20.             private string name;
  21.  
  22.             public Point(int x, int y)
  23.             {
  24.                 this.x = x;
  25.                 this.y = y;
  26.             }
  27.  
  28.             public Point(string name) : this(100, 300)
  29.             {
  30.                 this.name = name;
  31.             }
  32.  
  33.             public Point(string name, int x, int y) : this(x, y)
  34.             {
  35.                 this.name = name;
  36.             }
  37.            
  38.             public (int,int) GetCoodrds() => (this.x,this.y);
  39.             public string GetName() => this.name;
  40.             public (string, int, int) GetCoordsAndName => (this.name, this.x, this.y);
  41.         }
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement