???????????????
????????????????????????????????????”??????”??????????????????????”???????”???????????????????”?????”?????????????????????????????????????Щ??????????п?????????????????????????δ????????????????????????????????????????????????????????
????????????IL????
???????濴??????????????????ж???????????????????????????int????????
????namespace GenericTest
????{
????class CompareUtil<T>where T:IComparable
????{
????public T ItemOne{get;set;}
????public T ItemTwo{get;set;}
????public CompareUtil(T itemOne??T itemTwo)
????{
????this.ItemOne=itemOne;
????this.ItemTwo=itemTwo;
????}
????public T GetBiggerOne()
????{
????if(ItemOne.CompareTo(ItemTwo)>0)
????{
????return ItemOne;
????}
????return ItemTwo;
????}
????}
????class IntCompareUtil
????{
????public int ItemOne{get;set;}
????public int ItemTwo{get;set;}
????public IntCompareUtil(int itemOne??int itemTwo)
????{
????this.ItemOne=itemOne;
????this.ItemTwo=itemTwo;
????}
????public int GetBiggerOne()
????{
????if(ItemOne.CompareTo(ItemTwo)>0)
????{
????return ItemOne;
????}
????return ItemTwo;
????}
????}
????class Program
????{
????static void Main(string[]args)
????{
????CompareUtil<int>compareInt=new CompareUtil<int>(3??6);
????int bigInt=compareInt.GetBiggerOne();
????IntCompareUtil intCompareUtil=new IntCompareUtil(4??7);
????int big=intCompareUtil.GetBiggerOne();
????Console.Read();
????}
????}
????}
????????????ILSpy????·?????”CompareUtil<T>”??IL??????г????????IL????
????.class private auto ansi beforefieldinit GenericTest.CompareUtil`1<([mscorlib]System.IComparable)T>
????extends[mscorlib]System.Object
????{
????……
????.method public hidebysig specialname rtspecialname
????instance void.ctor(
????!T itemOne??
????!T itemTwo
????)cil managed
????{……}
????……
????//Properties
????.property instance!T ItemOne()
????{
????.get instance!0 GenericTest.CompareUtil`1::get_ItemOne()
????.set instance void GenericTest.CompareUtil`1::set_ItemOne(!0)
????}
????.property instance!T ItemTwo()
????{
????.get instance!0 GenericTest.CompareUtil`1::get_ItemTwo()
????.set instance void GenericTest.CompareUtil`1::set_ItemTwo(!0)
????}
????}//end of class GenericTest.CompareUtil`1
??????????????????”IntCompareUtil”??IL???????????????IL?????????????IL?????????£??????????IL?????ж????Щ?????????????