Wednesday, March 29, 2017

New Features–Out Variables in C# 7.0

Prior to C# 7.0,  For out keyword, we need to define that variable earlier and then we were able to pass that variable as out reference arguments. But now with C# 7.0, You don’t need to declare the variable but you can use the variable which you have used in arguments.

Following is a code showing both ways passing out variables.

In the above code, You can see that I have created get employee static method which put some values in this out variables. First I have shown the old way of doing this. Where I explicitly defined the variables and then passed it to function while in the new way of doing you don’t need to explicitly define variable. You can write this as an argument and then, later on, you can use the same variable in next statements.  Now when you run the application, the new and old way both produce the same output.


csharp7-out-varibles-example

You can find complete source code of this examples at following location on Github at- https://github.com/dotnetjalps/CSharp7NewFeatures
Share:

0 comments:

Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews