Methods overloading with value and reference parameter types

前端 未结 4 1484
囚心锁ツ
囚心锁ツ 2021-02-14 06:24

I have the following code :

class Calculator
    {
        public int Sum(int x, int y)
        {
            return x + y;
        }



        public int Sum(o         


        
4条回答
  •  花落未央
    2021-02-14 06:45

    This is by specification. According to MSDN page out parameter modifier (C# Reference)

    Although the ref and out keywords cause different run-time behavior, they are not considered part of the method signature at compile time. Therefore, methods cannot be overloaded if the only difference is that one method takes a ref argument and the other takes an out argument. The following code, for example, will not compile:

提交回复
热议问题