Follow on Google News News By Tag Industry News * C# Programming * More Industries... News By Location Country(s) Industry News
Follow on Google News | How to use C# out parameter in programming?In order to return multiple output values from a single function in C#, the out keyword is used. It makes able to a function to return multiple values in same time.
By: Steven Clark In order to use output parameter in C# function, you will have to use out keyword with variable name. It takes variable as output parameter and uses this variable to storing values returning from the function. For example, you have a function calculation that takes two integer values as input but returns four value as output like addition, subtraction, multiplication and division. In this situation the out keyword will use with variable name for assigning that the variable is output parameter. Consider the following programming example: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace out_parameter { class Program { public static void calculation( { add = num1 + num2; sub = num1 - num2; mul = num1 * num2; div = num1 / num2; } static void Main(string[] { int addresult, subresult, mulresult; float divresult; Program.calculation( Console.WriteLine(" Console.WriteLine(" Console.WriteLine(" Console.WriteLine(" Console.ReadLine(); } } } In the preceding example, we created a static function calculation that takes two input parameter as num1 and num2 and returns four out parameter as out int add, out int sub, out int mul, out float div. In the Main() function we call this function and store the output in four different variable as addresult, subresult, mulresult and divresult. It is very easy to use out parameter in C# programming. It is also very important function that makes your program easier and simpler. You don’t need to create multiple functions for doing same group of task. Just create single function and return number of value as you want. For more info about C# out parameter, please visit to: http://www.completecsharptutorial.com/ End
Account Email Address Account Phone Number Disclaimer Report Abuse
|
|