Csharp/C Sharp/Generics/Generic struct

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Demonstrate a generic struct

<source lang="csharp"> using System; struct XY<T> {

 T x;
 T y;
 public XY(T a, T b) {
   x = a;
   y = b;
 }
 public T X {
   get { return x; }
   set { x = value; }
 }
 public T Y {
   get { return y; }
   set { y = value; }
 }

} class StructTest {

 public static void Main() {
   XY<int> xy = new XY<int>(1, 2);
   XY<double> xy2 = new XY<double>(8.0, 9.0);
   Console.WriteLine(xy.X + ", " + xy.Y);
   Console.WriteLine(xy2.X + ", " + xy2.Y);
 }

}

      </source>