您的位置:首页 > 其它

自定义泛型方法

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>

但是除了这些方法外,还可以自定义方法哦。

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

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: