C# 7.0 New Features Series [ Out variables ]

Out variables are also enhanced for syntactic sugar in C# 7.0. In earlier version you were needed to declare variables with full types (not with var) to be able to assign it as out variables in a method. It did not use to serve any purpose to declare the variable before being used as out arguments as they had to be overwritten after all. So in newer version now the syntax is a bit enhanced to reduce that unnecessary declaration step prior to use.

Now you can just declare the variable right there in the method call when you are using it as out variable. Following are two code listings. The first one is showing the old version and the second one is showing the newer version of the code.

oldoutvar

OLD VERSION OF OUT VARIABLE

 

outfeatureprogram70C# 7.0 FEATURE OF OUT VARIABLE

 

One more improvement over the previous version of the out variable is that you can declare it with var keyword instead of the full type name.

outwithvar

OUT VARIABLES WITH VAR KEYWORD

  • Show Comments (0)

Your email address will not be published. Required fields are marked *

comment *

  • name *

  • email *

  • website *