1、泛型方法

    1. using System;
    2. using System.Collections.Generic;
    3. namespace ConsoleApp53
    4. {
    5. class Program
    6. {
    7. static void Main(string[] args)
    8. {
    9. int[] a1 = { 1, 2, 3, 4, 5 };
    10. int[] a2 = { 1, 2, 3, 4, 5, 6 };
    11. double []a3 = { 1.1,2.2,3.3,4.4,5.5};
    12. double []a4 = { 1.1,2.2,3.3,4.4,5.5,6.6};
    13. var result = zip(a3, a4);
    14. Console.WriteLine(string.Join(",", result));
    15. }
    16. static T[] zip<T>(T[] a, T[] b)
    17. {
    18. T[] zipped = new T[a.Length + b.Length];
    19. int ai = 0;
    20. int bi = 0;
    21. int zo =0;
    22. do
    23. {
    24. if (ai < a.Length) zipped[zo++] = a[ai++];
    25. if (bi< b.Length)
    26. {
    27. zipped[zo++] = b[bi++];
    28. }
    29. } while (ai < a.Length || bi< b.Length);
    30. return zipped;
    31. }
    32. }
    33. }

    2、泛型接口一

    using System;
    using System.Collections.Generic;
    
    namespace ConsoleApp53
    {
        class Program
        {
            static void Main(string[] args)
            {
                Student<int> student = new Student<int>();
                student.ID = 100;
                student.Name = "IT";
            }
        }
        interface IUqueni<TID>
        {
            TID ID { get; set; }
        }
        class Student<TID> : IUqueni<TID>
        {
            public TID ID { get ; set; }
            public string Name { get; set; }
        }
    }
    

    3、泛型接口二

    using System;
    using System.Collections.Generic;
    
    namespace ConsoleApp53
    {
        class Program
        {
            static void Main(string[] args)
            {
                Student student = new Student();
                student.Name = "IT";
                student.ID = 100;
            }
        }
        interface IUqueni<TID>
        {
            TID ID { get; set; }
        }
        class Student: IUqueni<int>
        {
            public string Name { get; set; }
            public int ID { get ; set ; }
        }
    }