自定义泛型方法
2008-06-24 09:41
211 查看
泛型的接口主要有:ICollection<T>,IComparer<T>,IDictionary<T>,IEnumerable<T>,IEnumerator<T>,IList<T>;
已经实现的类有:Collection<T>,Comparer<T>, Dictionary<T>, List<T>, Queue<T>, SortedDictionary<T>, Stack<T>,LinkedList<T>,ReadOnlyCollection<T>
但是除了这些方法外,还可以自定义方法哦。
已经实现的类有:Collection<T>,Comparer<T>, Dictionary<T>, List<T>, Queue<T>, SortedDictionary<T>, Stack<T>,LinkedList<T>,ReadOnlyCollection<T>
但是除了这些方法外,还可以自定义方法哦。
public static void Swap<T>(ref T a, ref T b) { T temp; temp = a; a = b; b = temp; } static void Main(string[] args) { int a = 3; int b = 4; Swap<int>(ref a,ref b); Console.WriteLine(a.ToString() + "," + b.ToString()); string s1 = "hello"; string s2 = "world"; Swap<string>(ref s1,ref s2); Console.WriteLine(s1 + s2); }
相关文章推荐
- 自定义泛型方法的练习与类型推断总结
- 自定义泛型类型和方法
- 116_容器_自定义泛型_泛型类_泛型接口_泛型方法_安全_省心
- Java学习笔记之泛型(二):在方法上自定义泛型
- java自定义泛型(泛形)方法
- java泛型-自定义泛型方法与类型推断总结
- 跟王老师学泛型(五): 自定义带泛型声明的方法
- Java自定义泛型类和泛型方法
- java再复习——自定义泛型方法
- 用LinQ扩展方法,泛型扩展方法,实现自定义验证字符是否空、对象是否为null,及泛型约束使用,Action的使用
- List<T>泛型数组API自带的Sort() 排序方法根据自定义排序实现
- 泛型(2)——方法上自定义泛型
- 16.6 方法上自定义泛型
- 117_容器_自定义泛型_深入1_子类_属性类型_重写方法类型_泛型擦除
- 泛型集合 and 自定义泛型方法
- LinQ 泛型方法Array>ForEach在数组中进行迭代并调用自定义的委托
- 自定义泛型方法及其应用
- 7.6.4 自定义泛型的方法和使用
- 自定义泛型方法及其应用和类型参数的类型推断
- java泛型学习-自定义泛型方法与类型推断总结