摘要:
1 #region Generic structuer 2 public struct Point<T> 3 { 4 //Generic state date. 5 private T xPos; 6 private T yPos; 7 //Generic constructor. 8 public Point(T xVal, T yVal) 9 {10 xPos = xVal;11 yPos = yVal;12 }1... 阅读全文
摘要:
用自定义泛型实现交换任意类型的两个变量。 1 class Program 2 { 3 static void Main(string[] args) 4 { 5 int a = 10, b = 90; 6 Console.WriteLine("Before swap: {0}, {1}", a, b); 7 Swap<int>(ref a, ref b); 8 Console.WriteLine("After swap: {0}, {1}", a, b); 9... 阅读全文