Advertisement
kadyr

Untitled

Dec 20th, 2022
787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1.  
  2. public class Point2D<T>
  3. {
  4.     public T x;
  5.  
  6.     public T y;
  7.  
  8.     public Point2D(T x, T y)
  9.     {
  10.         this.x = x;
  11.         this.y = y;
  12.     }
  13. }
  14.  
  15. public class Z<T> : Point2D<T>
  16. {
  17.     public T z { get; set; }
  18.  
  19.     public Z(T x, T y, T z) : base(x, y)
  20.     {
  21.         this.z = z;
  22.     }
  23. }
  24.  
  25. public class Point3D<T> : Z<T>
  26. {
  27.     public Point3D(T x, T y, T z) : base(x, y, z)
  28.     {
  29.     }
  30.  
  31.     public string GetPoint()
  32.     {
  33.         return "x +" + x + " y +" + y + " z +" + z;
  34.     }
  35. }
  36.  
  37. public static class Program
  38. {
  39.  
  40.     public static void Main(string[] args)
  41.     {
  42.  
  43.  
  44.         Console.WriteLine(array[0].GetName());
  45.  
  46.         Point3D<int> point1 = new Point3D<int>(1, 5, 3);
  47.         Point3D<char> point2 = new Point3D<char>('4', '1', '2');
  48.         Point3D<string> point3 = new Point3D<string>("5", "4", "2");
  49.         Point3D<float> point4 = new Point3D<float>(5f, 4f, 2f);
  50.  
  51.         Console.WriteLine(point1.GetPoint());
  52.         Console.WriteLine(point2.GetPoint());
  53.         // Console.WriteLine(point3.GetPoint());
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement