作者:不及格的程序员-八神
事起有音:
相关链接
http://www.cnblogs.com/allenlooplee/archive/2007/01/22/627386.html System.Object 是 .NET 中所有类型的根吗
http://www.cnblogs.com/anytao/archive/2009/03/05/must_net_27.html interface到底继承于object吗
看看吧,后果很严重,知道又能怎么样呢, 谁知道你的类父类是什么,就连CLR都不知道,你还指望谁?
接口根继承Object有直接关系吗? 没有,接口:契约而,那它方法从哪来-----因为引用类型的方法表中有定义(CLR自动为你生成).
源码:
1
3 using System;
4
5 namespace Test
6 {
7 public interface ITest
8 {
9 void No();
10 }
11
12 public class Obj1
13 {
14 }
15
16 public class Obj2 : ITest
17 {
18 public void No(){}
19 }
20
21 }
3 using System;
4
5 namespace Test
6 {
7 public interface ITest
8 {
9 void No();
10 }
11
12 public class Obj1
13 {
14 }
15
16 public class Obj2 : ITest
17 {
18 public void No(){}
19 }
20
21 }
中间码:


1
2
3
4 // Microsoft (R) .NET Framework IL Disassembler. Version 3.5.30729.1
5
6
7
8
9 // Metadata version: v2.0.50727
10 .assembly extern mscorlib
11 {
12 .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
13 .ver 2:0:0:0
14 }
15 .assembly '1'
16 {
17 .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
18 .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 //

19 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
20 .hash algorithm 0x00008004
21 .ver 0:0:0:0
22 }
23 .module '1.dll'
24 // MVID: {176435F4-DB87-437C-A621-B1370EF3AB88}
25 .imagebase 0x00400000
26 .file alignment 0x00000200
27 .stackreserve 0x00100000
28 .subsystem 0x0003 // WINDOWS_CUI
29 .corflags 0x00000001 // ILONLY
30 // Image base: 0x03360000
31
32
33 // =============== CLASS MEMBERS DECLARATION ===================
34
35 .class interface public abstract auto ansi Test.ITest
36 {
37 .method public hidebysig newslot abstract virtual
38 instance void No() cil managed
39 {
40 } // end of method ITest::No
41
42 } // end of class Test.ITest
43
44 .class public auto ansi beforefieldinit Test.Obj1
45
46 {
47 .method public hidebysig specialname rtspecialname
48 instance void .ctor() cil managed
49 {
50 // 代码大小 7 (0x7)
51 .maxstack 8
52 IL_0000: nop
53 IL_0001: ret
54 } // end of method Obj1::.ctor
55
56 } // end of class Test.Obj1
57
58 .class public auto ansi beforefieldinit Test.Obj2
59
60 implements Test.ITest
61 {
62 .method public hidebysig newslot virtual final
63 instance void No() cil managed
64 {
65 // 代码大小 2 (0x2)
66 .maxstack 8
67 IL_0000: nop
68 IL_0001: ret
69 } // end of method Obj2::No
70
71 .method public hidebysig specialname rtspecialname
72 instance void .ctor() cil managed
73 {
74 // 代码大小 7 (0x7)
75 .maxstack 8
76 IL_0000: nop
77 IL_0001: ret
78 } // end of method Obj2::.ctor
79
80 } // end of class Test.Obj2
81
82
83 // =============================================================
84
85 // *********** 反汇编完成 ***********************
86 //