Exploring C# 7.0: Out Variables

In this series, I want to explore a couple of the new C# 7.0 features coming down the pipeline. As with most things, I am working with preview bits, so these features are not guaranteed to work the same way in production.

Using the out keyword within C# is nothing new. If you declare a variable within a method called with out, you are instructing the compile that you are expecting the method to set the values of those at runtime.

Commonly the problem is that you have to declare the variable before the method call using out. In C# 7.0, there is the concept of out variables, which will save you a couple keystrokes by allowing you to declare the variable inline.

The above example can be quickly refactored:

Originally published on 2016-11-08 in Development - C#

Enjoy this article? Let's keep in touch

I really appreciate you taking the time out of your schedule to read this post. I like to keep my friends updated on new articles and also spawn discussions here and there.

If you'd like to keep in touch, please subscribe below. And I promise, no more than 1 email per week (if even that).