您的位置:首页 > 编程语言 > C#

C# 不能使用的方法

2010-05-15 18:45 183 查看
1.  属性
设置一个属性   
Public    返回值类型   属性名
         Get     返回值                                          取属性值
         Set                                                                     设置属性值
 
 
         编译器生成代码
.method public hidebysig specialname instance int32
        get_变量名() cil managed
{
  // Code size       7 (0x7)
  .maxstack  1
  .locals init ([0] int32 CS$1$0000)
  IL_0000:  nop
  IL_0001:  ldc.i4.1
  IL_0002:  stloc.0
  IL_0003:  br.s       IL_0005
  IL_0005:  ldloc.0
  IL_0006:  ret
} // end of method Class1::get_Item
 
.method public hidebysig specialname instance void
        set_变量名(int32 'value') cil managed
{
  // Code size       2 (0x2)
  .maxstack  8
  IL_0000:  nop
  IL_0001:  ret
} // end of method Class1::set_Item
 
.property instance int32 变量名()
{
  .get instance int32 ConsoleApplication2.Class1::get_变量名()
  .set instance void ConsoleApplication2.Class1::set_变量名(int32)
} // end of property Class1::Item
 
所以可以看出 当我们写了属性后 编译器自己添加方法int  get_变量名()  和 void set_变量名(int32 i)
自然我们就不能再写方法
Public int get_变量名()
{}
 
Public void Set_变量名(int index)
{}
2.  方法
 public int this[int index]
 {
     get
     {
        return 1;
     }
     }
 
     编译器生成代码
 
.method public hidebysig specialname instance int32
        get_Item(int32 index) cil managed
{
  // Code size       7 (0x7)
  .maxstack  1
  .locals init ([0] int32 CS$1$0000)
  IL_0000:  nop
  IL_0001:  ldc.i4.1
  IL_0002:  stloc.0
  IL_0003:  br.s       IL_0005
  IL_0005:  ldloc.0
  IL_0006:  ret
} // end of method Class1::get_Item
 
 
.property instance int32 Item(int32)
{
  .get instance int32 ConsoleApplication2.Class1::get_Item(int32)
} // end of property Class1::Item
 
编译器自己添加方法int  get_Item(int  index)
自然我们也不能添加方法 int  get_Item(int  index)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# 编译器 cil class
相关文章推荐