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)
设置一个属性
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)
相关文章推荐
- win7中C#的winForm编程使用savefiledialog不能弹出保存窗体的解决方法
- C#错误:不能以方法的方式使用不可调用的
- EasyJoyStick使用以及两种操作杆 EasyJoyStick的使用方法,简单的不能再简单 Hedgehog Team-》Easy Touch -》Add Easy Touch For C#
- C# 匿名方法和拉姆达表达式 (2012-04-27 23:27:15)转载▼ 标签: 杂谈 匿名方法本质上是一传递给委托的代码块,是使用委托的另一种方法。 规则: 1、匿名方法中不能使用跳转语句跳
- 【C#】不能像使用方法那样使用不可调用的成员"System.Data.DataSet.Tables".
- c#中跨线程调用windows窗体控件 .我们在做winform应用的时候,大部分情况下都会碰到使用多线程控制界面上控件信息的问题。然而我们并不能用传统方法来做这个问题,下面我将详细的介绍。
- 【原创】开源Math.NET基础数学类库使用(12)C#随机数扩展方法
- C# split 使用方法
- C#使用oledb连接excel运行Insert Into语句出现“操作必须使用一个可更新的查询”的解决的方法
- 使用github上的开源框架SlidingMenu环境的搭建,以及getSupportActionBar方法不能找到的问题
- 使用C#ping主机的方法
- iOS9中友盟分享不能使用 破解方法
- C# 中SqlParameter类的使用方法小结
- C#HttpClient或使用CookieContainer模拟登陆后HttpRequest不发送cookie的解决方法及原因
- C# 使用Linq递归查询数据库遇到的问题及解决方法
- 有何方法使别人不能在自己的电脑使用u盘
- 关于在extjs中使用column布局,不能显示textfield的标签(fieldLabel)解决方法
- C#使用StackTrace获取方法被谁调用
- C#中winform使用相对路径读取文件的方法
- C#将时间转成文件名使用方法