Methods overloading with value and reference parameter types

前端 未结 4 1477
囚心锁ツ
囚心锁ツ 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:52

    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.

    Also see: ref (C# Reference)

    Members of a class can't have signatures that differ only by ref and out. A compiler error occurs if the only difference between two members of a type is that one of them has a ref parameter and the other has an out parameter.

提交回复
热议问题