Multi-value Return in C# 7.0

Written by on February 3, 2017 in Programming with 0 Comments

One of the nice language enhancements to C# in the latest release (7.0) is the ability to return multiple values from a function. Although one could use Tuples for this purpose, it is not an elegant or efficient approach. For more details, see this article.

By the way, returning multiple values from a function is not unique to C#. It is available in many languages. In an earlier article, I showed how Lisp supports this feature.

The following example shows how to use this feature in C#. I tried this in Visual Studio Professional 2017 RC (you have to add System.ValueTuple NuGet package to the current project to get this working.)

Multi-value Return in C#

Multi-value Return in C#

As you can see, returning multiple values from a function makes a lot of sense when the values are logically related.

Just for comparison, I am giving below the same functionality implemented in Lisp.

Multi-value Return in Lisp

Multi-value Return in Lisp

If you would like more details on this feature as supported in Lisp, take a look at this blog.

Have a great day!

Tags: , ,

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

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

Top