摘要: where T : struct The type parameter <T> must have System.ValueType in its chain of inheritance; in other words, <T> must be a structure. where T : class The type parameter <T> must not have System.ValueType in its chain of inheritance (e.g., <T> must be ... 阅读全文
posted @ 2013-04-26 11:18 张楠0412 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 1 class Program 2 { 3 #region Person class for testing 4 public class Person 5 { 6 public int Age { get; set; } 7 public string FirstName { get; set; } 8 public string LastName { get; set; } 9 10 public Person() 1... 阅读全文
posted @ 2013-04-26 11:13 张楠0412 阅读(226) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2013-04-26 10:27 张楠0412 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 用自定义泛型实现交换任意类型的两个变量。 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... 阅读全文
posted @ 2013-04-26 10:01 张楠0412 阅读(186) 评论(0) 推荐(0) 编辑