Out Parameters : out « Language Basics « C# / CSharp Tutorial






using System;
class Point
{
    public Point(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
    
    public void GetPoint(out int x, out int y)
    {
        x = this.x;
        y = this.y;
    }
    
    int x;
    int y;
}

class MainClass
{
    public static void Main()
    {
        Point myPoint = new Point(10, 15);
        int x;
        int y;
        
        myPoint.GetPoint(out x, out y);
        Console.WriteLine("myPoint({0}, {1})", x, y);
    }
}
myPoint(10, 15)








1.12.out
1.12.1.Use 'out' keyword (no need to assign because it is an out)
1.12.2.Ref and Out Parameters
1.12.3.Out Parameters
1.12.4.Use out
1.12.5.Use two out parameters