Generic Method Demo : Generic Method « Generic « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.ComponentModel;

    class GenericMethodDemo
    {
        static List<T> MakeList<T> (T first, T second)
        {
            List<T> list = new List<T>();
            list.Add (first);
            list.Add (second);
            return list;
        }

        static void Main()
        {
            List<string> list = MakeList<string>("Line 1", "Line 2");
            foreach (string x in list)
            {
                Console.WriteLine(x);
            }
        }
    }








18.12.Generic Method
18.12.1.A generic method
18.12.2.constrained method calls
18.12.3.A generic method: constrol the parameter
18.12.4.Generic and non Generic compare
18.12.5.Generic Method Demo
18.12.6.Generic Method Reflection
18.12.7.Multiple Argument Inference with value and object