C# out parameters vs returns

后端 未结 5 1618
Happy的楠姐
Happy的楠姐 2021-01-11 17:17

So I am new to C# and I am having difficulty understanding out. As opposed to just returning something from a function

using System;
class Retur         


        
5条回答
  •  天涯浪人
    2021-01-11 17:37

    When one variable is concerned out and return are OK. But what if you wanted to return more than 1 values? Out helps in that.

    static void CalculateArea(out double r, out double Foo)
    {
        //Can return 2 values in terms of out variables.
    }
    
    static double CalculateArea(double r)
    {
         // Will return only one value.
    }
    

提交回复
热议问题