首页 新闻 会员 周边

IL中用于修饰方法的hidebysig是什么含义

0
悬赏园豆:80 [已解决问题] 解决于 2011-12-13 10:11

查了不少资料,都说如果一个类中的方法被hidebysig修饰时,那么在这个类作为父类被别的类继承时,hidebysig修饰的方法不会被继承,可是对于下面的代码

public class ClassA
{
public void Foo1()
{ }
}

class ClassB:ClassA
{
}

编译后ClassA的方法Foo1的代码为

.method public hidebysig instance void  Foo1() cil managed
{
.maxstack 8
IL_0000: nop
IL_0001: ret
}

但是类ClassB的实例可以访问方法Foo1(),这说明方法Foo1被ClassB继承了。那么这个关键字到底是什么含义


c# il
Lukexywang的主页 Lukexywang | 初学一级 | 园豆:178
提问于:2011-12-12 21:53
< >
分享
最佳答案
1

hidebysig means HIDE (a method) BY (its) SIGnature, 就是new关键字的效果。

收获园豆:80
水牛刀刀 | 大侠五级 |园豆:6350 | 2011-12-13 10:08
其他回答(2)
1

我也找了一下资料,应该是作为父类使用时不能被子类覆盖吧!我也没有仔细了解。你有正确的了解,通知一下啊!

小小刀 | 园豆:1991 (小虾三级) | 2011-12-13 00:12

从stackoverflow上找到的答案:hidebysig is supplied for the use of tools and is ignored by the VES. It specifies that the declared method hides all methods of the base class types that have a matching method signature; when omitted, the method should hide all methods of the same name, regardless of the signature.

上面的英文摘自ECMA关于CLI的标准。用hidebysig修饰的方法会隐藏掉积累中具有相同签名的方法,这么看来相当于在方法前加上了new关键字

支持(0) 反对(0) Lukexywang | 园豆:178 (初学一级) | 2011-12-13 09:14

@菜鸟.CS: 这样的话,我前面的理解就没有错了

支持(0) 反对(0) 小小刀 | 园豆:1991 (小虾三级) | 2011-12-13 23:46
0

hidebysig is supplied for the use of tools and is ignored by the VES. It specifies that the declared method hides all methods of the base class types that have a matching method signature; when omitted, the method should hide all methods of the same name, regardless of the signature.

上面的英文摘自ECMA关于CLI的标准。用hidebysig修饰的方法会隐藏掉积累中具有相同签名的方法,这么看来相当于在方法前加上了new关键字

Lukexywang | 园豆:178 (初学一级) | 2011-12-13 09:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册