usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceMyGeneirc{internalclassProgram{staticvoidMain(string[] args){try{People people =newPeople(){ Id =123, Name ="张三"};Chinese chinese =newChinese(){ Id =234, Name ="李四"};Hubei hubei =newHubei(){ Id =456, Name ="王五"};Japanese japanese =newJapanese(){ Id =678, Name ="田中"};
Console.WriteLine("****************约束基类***********************");//Constraint.Show<People>(people);
Constraint.Show<Chinese>(chinese);
Constraint.Show<Hubei>(hubei);//Constraint.Show<Japanese>(japanese); // 编译报错
Console.WriteLine("****************约束接口***********************");
Constraint.Get<Chinese>(chinese);}catch(Exception ex){
Console.WriteLine(ex.ToString());}
Console.ReadLine();}}}
本博客内容涉及到:切片
切片
1. 切片的概念
首先先对数组进行一下回顾:
数组定义完,长度是固定的,例如:
var num [5]int [5]int{1,2,3,4,5}定义的num数组长度是5,表示只能存储5个整形数字,…