when you are want to return any value from any method then you are use return keyword. But return keyword return only one value at a time. Let see in Example:
using System; classProgram { publicstaticvoid Main() { int result = 0; result = Add(10, 20); Console.WriteLine("Sum={0} ", result); Console.ReadKey(); } publicstaticint Add(int FN, int SN) { return FN + SN; } }
in this example method Add return a single value.
But at the same time i want to return more than one value from a method then return not do this operation.
So, that place we use out keyword.
Because out keyword used when you want a method to return more than one value.
Let see in below example
Example: I have a method Calculate and i want to it return two value first is Sum and second is Subtract of numbers
using System; classProgram { publicstaticvoid Main() { int Total = 0; int Subtract= 0; Calculate(10, 20, out Total, out Subtract); Console.WriteLine("Sum={0} &&Subtract={1}",Total,Subtract); Console.ReadKey(); } publicstaticvoid Calculate(int FN,int SN,outint Sum,outint Subtract) { Sum = FN + SN; Subtract= FN - SN; } }
OUTPUT:
I hope you are understand this.
Liked By
Write Answer
use of out parameter in c#
Join MindStick Community
You have need login or register for voting of answers or question.
Niraj Kumar Mishra
25-Aug-2017Let see in Example: