Method Signature in C#

前端 未结 7 807
误落风尘
误落风尘 2020-11-27 13:36

What is the Method Signature in the following

int DoSomething(int a, int b);

Return type is a part of signature or not???

7条回答
  •  野性不改
    2020-11-27 14:10

    In the case when method have generic arguments understanding of signature becomes more confusing.

    Generic types declaring on class level are considered as normal types.

    But generic types declaring on method level are considered as index in method's generic arguments.

    For example these all methods have different signatures.

    class MyClass
    {
        public void F(TValue v) { }       // generics: 0, arg: TValue
        public void F(TValue v) { }    // generics: 1, arg: TValue
        public void F(TValue v) { } // generics: 2, arg: TValue
    
        public void F(X v) { }    // generics: 1, arg: 0
        public void F(X v) { } // generics: 2, arg: 0
        public void F(Y v) { } // generics: 2, arg: 1
    }
    

提交回复
热议问题