Usually,
method or function returns a value with return keyword. A return keyword or
modifier can return only one value at a time. In some scenario, C# program
required to return multiple values from a single method or function. So if you
want a method or function should return multiple value then you use OUT
parameter.
Example:-
namespace ConsoleApplication1
{
class Sample
{
public string param1, param2;
public static void
AreaOfCircle(int radius,out double area,out double perimeter)
{
area = 3.14 * (radius * radius);
perimeter = 2 * 3.14 * radius;
}
}
class Program:Factory
{
static void Main(string[] args)
{
double
area;
double
perimeter;
Sample.AreaOfCircle(5,
out area, out
perimeter);
Console.Write("Area Of Circle:" + area);
Console.Write("Perimeter Of Circle:" + perimeter);
Console.ReadKey();
}
}
}
Output:-
Area Of Circle: 78.5
Perimeter Of Circle: 31.4
No comments:
Post a Comment
Note: only a member of this blog may post a comment.