What is the purpose of hidebysig in a MSIL method?

前端 未结 3 1196
独厮守ぢ
独厮守ぢ 2020-12-07 11:06

Using ildasm and a C# program e.g.

static void Main(string[] args)
{

}

gives:

.method private hidebysig static void  Main(         


        
3条回答
  •  -上瘾入骨i
    2020-12-07 11:18

    As per THE SKEET's answer, in addition the reason for this is that Java and C# allow the client of a class to call any methods with the same name, including those from base classes. Whereas C++ does not: if the derived class defines even a single method with the same name as a method in the base class, then the client cannot directly call the base class method, even if it doesn't take the same arguments. So the feature was included in CIL to support both approaches to overloading.

    In C++ you can effectively import one named set of overloads from the base class with a using directive, so that they become part of the "overload set" for that method name.

提交回复
热议问题