- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the improvements in Out Parameter in C# 7.0?
We can declare out values inline as arguments to the method where they're used.
The existing out parameters has been improved in this version. Now we can declare out variables in the argument list of a method call, rather than writing a separate declaration statement.
Advantages −
The code is easier to read.
No need to assign an initial value.
Existing Syntax −
Example
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(); } }
Output
15 50
New Syntax −
Example
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(); } }
Output
15 50
Advertisements