We can declare values inline as parameters for methods.
Now, the existing out parameters have been improved in this version. Now we can declare
Use out variables in the argument list of a method call instead of writing separate code Declaration statement.Advantages −
The code is more readable.
No need to assign an initial value.
Existing syntax −
class Program{ public static void AddMultiplyValues(int a, int b, out int c, out int d){ c = a + b; d = a * b; } public static void Main(){ int c; int d; AddMultiplyValues(5, 10, out c, out d); System.Console.WriteLine(c); System.Console.WriteLine(d); Console.ReadLine(); } }
15 50
New syntax −
class Program{ public static void AddMultiplyValues(int a, int b, out int c, out int d){ c = a + b; d = a * b; } public static void Main(){ AddMultiplyValues(5, 10, out int c, out int d); System.Console.WriteLine(c); System.Console.WriteLine(d); Console.ReadLine(); } }
15 50
The above is the detailed content of What improvements have been made to Out parameters in C# 7.0?. For more information, please follow other related articles on the PHP Chinese website!