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);
Constraint.Show<Chinese>(chinese);
Constraint.Show<Hubei>(hubei);//Constraint.Show(japanese); // 编译报错
Console.WriteLine("****************约束接口***********************");
Constraint.Get<Chinese>(chinese);}catch(Exception ex){
Console.WriteLine(ex.ToString());}
Console.ReadLine();}}}