1、泛型方法
using System;using System.Collections.Generic;namespace ConsoleApp53{class Program{static void Main(string[] args){int[] a1 = { 1, 2, 3, 4, 5 };int[] a2 = { 1, 2, 3, 4, 5, 6 };double []a3 = { 1.1,2.2,3.3,4.4,5.5};double []a4 = { 1.1,2.2,3.3,4.4,5.5,6.6};var result = zip(a3, a4);Console.WriteLine(string.Join(",", result));}static T[] zip<T>(T[] a, T[] b){T[] zipped = new T[a.Length + b.Length];int ai = 0;int bi = 0;int zo =0;do{if (ai < a.Length) zipped[zo++] = a[ai++];if (bi< b.Length){zipped[zo++] = b[bi++];}} while (ai < a.Length || bi< b.Length);return zipped;}}}
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 ; }
}
}
