Advertisement
damesova

DemoPointTamplateClass

Oct 7th, 2022
1,028
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. // Клас Точка в координатната система:
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5.  
  6.  
  7. namespace DemoPointTamplateClass
  8. {
  9.     public class Point<T>
  10.     {
  11.         private T x;
  12.         private T y;
  13.  
  14.         public T X
  15.         {
  16.             get { return x; }  
  17.             set { x = value;  }
  18.         }
  19.         public T Y
  20.         {
  21.             get { return y; }
  22.             set { y = value; }
  23.         }
  24.  
  25.         public void Info()
  26.         {
  27.             Console.WriteLine("Generic type: {0}", this.x.GetType());
  28.             Console.WriteLine("x={0}, y={1}", x,y);
  29.         }
  30.     }
  31. }
  32.  
  33. //Главен клас на програмата:
  34. namespace DemoPointTamplateClass
  35. {
  36.     internal class Program
  37.     {
  38.         static void Main(string[] args)
  39.         {
  40.             Point<int> point1 = new Point<int>();
  41.             point1.X = 100;
  42.             point1.Y = 100;
  43.             point1.Info();
  44.  
  45.             Point<double> point2 = new Point<double>();
  46.             point2.X = 10.01;
  47.             point2.Y = 100.12;
  48.             point1.Info();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement