C# 7 Inline Out Variables

A variable can be declared in C# 7 at the exact moment that it is supplied as an out argument.

Jin Vincent Necesario
1 min readOct 31, 2022
Photo by Arif Maulana on Unsplash

Introduction

Back in the old days, using C# earlier versions before version 7, developers when they use an out variable. They must first declare a variable (of the correct type of course) before using it as an out parameter.

Let’s see an example below.

Some developers would agree that this is quite inconvenient.

However, developers who have been developing for a while now seem to accept this old syntax. Honestly, I only encountered the newer syntax when Visual Studio auto-suggestion, suggesting to use of an inline out variable.

Using Inline Out Variable

Implement an inline out variable is easy. Developers need to insert the type of the out variable to the left of the variable name. Or developers can also use implicitly typed variables as inline out variables.

Let’s see an example below.

Till next time. See yeah. Cheers and bye.

--

--