ref and out modifiers and method overloading

ref and out modifiers are part of the method signature.


class Math
{
    int add(int i, int j)
    {
        return i + j;
    }
    int add(ref int i, ref int j){
        return i + j;
   }
}

ref and out cannot coexist


class Math
{
    int add(out int i, out int j)
    {
        return i + j;
    }
    int add(ref int i, ref int j){
        return i + j;
   }
}

Compile time error:


C:\g>csc Program.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.

Program.cs(9,9): error CS0663: Cannot define overloaded method 'add' because it
        differs from another method only on ref and out
Program.cs(5,9): (Location of symbol related to previous error)
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.