Since the out variables are declared directly as arguments to out parameters, the compiler can usually tell what their type should be (unless there are conflicting overloads), so it is fine to use var instead of a type to declare them:Ī common use of out parameters is the Try. Many kinds of statements do not establish their own scope, so out variables declared in them are often introduced into the enclosing scope. Note that the variables are in scope in the enclosing block, so that the subsequent line can use them. In C# 7.0 we have added out variables the ability to declare a variable right at the point where it is passed as an out argument:
#Microsoft visual studio 2017 new features full#
Since you typically aren’t initializing these variables (they are going to be overwritten by the method after all), you also cannot use var to declare them, but need to specify the full type: Before you can call a method with out parameters you first have to declare variables to pass to it. In older versions of C#, using out parameters isn’t as fluid as we’d like. Mads Torgersen, C# Language PM Out variables In the final version of C# 7.0 a few details have changed, some of them in response to great feedback on that post. If this post feels familiar, it may be because a preliminary version went out last August. If you are curious about the design process that led to this feature set, you can find design notes, proposals and lots of discussion at the C# language design GitHub site. We hope that they all combine to make your code more efficient and clear, and you more happy and productive. But there are many other features big and small. Perhaps the biggest features are tuples, which make it easy to have multiple results, and pattern matching which simplifies code that is conditional on the shape of data.
Here is a description of all the new language features in C# 7.0, which came out last Tuesday as part of the Visual Studio 2017 release.Ĭ# 7.0 adds a number of new features and brings a focus on data consumption, code simplification and performance.