Demonstrate a generic struct : Generic struct : Generics C# Source Code


Custom Search

C# Source Code » Generics » Generic struct »

 

Demonstrate a generic struct









    

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);
  }
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Generics
» Generic struct