{"id":476,"date":"2017-02-03T06:07:15","date_gmt":"2017-02-03T06:07:15","guid":{"rendered":"http:\/\/www.rangakrish.com\/?p=476"},"modified":"2017-04-08T08:22:21","modified_gmt":"2017-04-08T08:22:21","slug":"multi-value-return-in-c-7-0","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2017\/02\/03\/multi-value-return-in-c-7-0\/","title":{"rendered":"Multi-value Return in C# 7.0"},"content":{"rendered":"<p>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 <em><strong>Tuples<\/strong><\/em> for this purpose, it is not an elegant or efficient approach. For more details, see this <a href=\"https:\/\/blogs.msdn.microsoft.com\/dotnet\/2016\/08\/24\/whats-new-in-csharp-7-0\/\" target=\"_blank\">article<\/a>.<\/p>\n<p>By the way, returning multiple values from a function is not unique\u00a0to C#. It is available in many languages. In an earlier <a href=\"http:\/\/www.rangakrish.com\/index.php\/2016\/01\/06\/lisp-returning-multiple-values-from-a-function\/\" target=\"_blank\">article<\/a>, I showed how Lisp supports this feature.<\/p>\n<p>The following example shows how to use this feature in C#. I tried this in Visual Studio Professional 2017 RC (you have to add <em><strong>System.ValueTuple<\/strong><\/em> NuGet package to the current project to get this working.)<\/p>\n<figure id=\"attachment_477\" aria-describedby=\"caption-attachment-477\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/C-multi-valie.jpg\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"477\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2017\/02\/03\/multi-value-return-in-c-7-0\/c-multi-valie\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/C-multi-valie.jpg\" data-orig-size=\"776,704\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Rangarajan&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1486120192&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Multi-value Return in C#\" data-image-description=\"&lt;p&gt;Multi-value Return in C#&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Multi-value Return in C#&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/C-multi-valie.jpg\" class=\"wp-image-477\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/C-multi-valie.jpg?resize=650%2C590\" alt=\"Multi-value Return in C#\" width=\"650\" height=\"590\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/C-multi-valie.jpg?w=776&amp;ssl=1 776w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/C-multi-valie.jpg?resize=300%2C272&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/C-multi-valie.jpg?resize=768%2C697&amp;ssl=1 768w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><figcaption id=\"caption-attachment-477\" class=\"wp-caption-text\"><strong>Multi-value Return in C#<\/strong><\/figcaption><\/figure>\n<p>As you can see, returning multiple values from a function makes a lot of sense when the values are logically related.<\/p>\n<p>Just for comparison, I am giving below the same functionality implemented in Lisp.<\/p>\n<figure id=\"attachment_478\" aria-describedby=\"caption-attachment-478\" style=\"width: 617px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/Lisp-multi-value.jpg\"><img data-recalc-dims=\"1\" decoding=\"async\" data-attachment-id=\"478\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2017\/02\/03\/multi-value-return-in-c-7-0\/lisp-multi-value\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/Lisp-multi-value.jpg\" data-orig-size=\"617,351\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;Rangarajan&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1486120082&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Multi-value Return in Lisp\" data-image-description=\"&lt;p&gt;Multi-value Return in Lisp&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Multi-value Return in Lisp&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/Lisp-multi-value.jpg\" class=\"size-full wp-image-478\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/Lisp-multi-value.jpg?resize=617%2C351\" alt=\"Multi-value Return in Lisp\" width=\"617\" height=\"351\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/Lisp-multi-value.jpg?w=617&amp;ssl=1 617w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2017\/02\/Lisp-multi-value.jpg?resize=300%2C171&amp;ssl=1 300w\" sizes=\"(max-width: 617px) 100vw, 617px\" \/><\/a><figcaption id=\"caption-attachment-478\" class=\"wp-caption-text\"><strong>Multi-value Return in Lisp<\/strong><\/figcaption><\/figure>\n<p>If you would like more details on this feature as supported in Lisp, take a look at\u00a0this <a href=\"http:\/\/www.rangakrish.com\/index.php\/2016\/01\/06\/lisp-returning-multiple-values-from-a-function\/\" target=\"_blank\">blog<\/a>.<\/p>\n<p>Have a great day!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[17],"tags":[91,19,90],"class_list":["post-476","post","type-post","status-publish","format-standard","hentry","category-programming","tag-c-sharp","tag-lisp","tag-multi-value"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-7G","jetpack-related-posts":[{"id":122,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/01\/06\/lisp-returning-multiple-values-from-a-function\/","url_meta":{"origin":476,"position":0},"title":"Lisp: Returning Multiple Values From A Function","author":"admin","date":"January 6, 2016","format":false,"excerpt":"One of the interesting features of Lisp is its support for returning multiple values from a function, without bundling the values in a special container. Languages such as Python and Ruby support multi-value return (although there are subtle differences from Lisp). In C++11, we can use std::make_tuple() and std::tie(). To\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":558,"url":"https:\/\/www.rangakrish.com\/index.php\/2017\/07\/07\/clpython-python-in-common-lisp\/","url_meta":{"origin":476,"position":1},"title":"CLPython &#8211; Python in Common Lisp","author":"admin","date":"July 7, 2017","format":false,"excerpt":"My work in the area of NLP requires\u00a0me to work with several frameworks across multiple languages such as Java, Python and Lisp. Sometime ago I got a chance to experiment with CLPython, an open-source implementation of Python in Common Lisp. Although CLPython is not under active development now, I found\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2057,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/07\/19\/calling-lisp-functions-from-elixir\/","url_meta":{"origin":476,"position":2},"title":"Calling Lisp Functions from Elixir","author":"admin","date":"July 19, 2020","format":false,"excerpt":"In the last article\u00a0I showed how we can simulate the idea of Lisp's \"closure\" in Elixir. Today, I would like to demonstrate how we can call Lisp functions from Elixir using the NIF interface. What is the need to integrate Elixir with another language? I can think of two reasons:\u2026","rel":"","context":"In &quot;Elixir&quot;","block_context":{"text":"Elixir","link":"https:\/\/www.rangakrish.com\/index.php\/category\/elixir\/"},"img":{"alt_text":"Using the Lisp Functions","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/07\/Session.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/07\/Session.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/07\/Session.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/07\/Session.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":963,"url":"https:\/\/www.rangakrish.com\/index.php\/2018\/06\/24\/calling-go-functions-from-lisp-part-2\/","url_meta":{"origin":476,"position":3},"title":"Calling Go Functions from Lisp &#8211; Part 2","author":"admin","date":"June 24, 2018","format":false,"excerpt":"In my earlier article Calling Go Functions from Lisp, I explained the steps for making calls to Go functions from another language, specifically LispWorks Lisp. Today, I want to give a slightly more\u00a0 interesting example showing the use of Go channels\u00a0through exported functions. Go is widely admired for its native\u2026","rel":"","context":"In &quot;Golang&quot;","block_context":{"text":"Golang","link":"https:\/\/www.rangakrish.com\/index.php\/category\/golang\/"},"img":{"alt_text":"Go Functions","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2018\/06\/Go-Functions.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3199,"url":"https:\/\/www.rangakrish.com\/index.php\/2023\/09\/04\/simulating-python-zip-in-lisp\/","url_meta":{"origin":476,"position":4},"title":"Simulating Python Zip in Lisp","author":"admin","date":"September 4, 2023","format":false,"excerpt":"The zip() function in Python is a convenient mechanism for iterating over multiple \u201citerables\u201d in parallel. Looping over lists is a common scenario. Here is the output generated by the above code: Common Lisp does not have such a feature built into the language or as part of the standard\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Python Zip() Feature","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2023\/09\/python-code-300x99.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3675,"url":"https:\/\/www.rangakrish.com\/index.php\/2025\/04\/24\/interfaces-without-inheritance-comparing-c-and-common-lisp\/","url_meta":{"origin":476,"position":5},"title":"Interfaces Without Inheritance: Comparing C++ and Common Lisp","author":"admin","date":"April 24, 2025","format":false,"excerpt":"Clean interface design is a crucial aspect of software engineering since it enables code flexibility, reuse, and maintainability. Developers who prefer an object-oriented approach typically rely on inheritance to define the interface and thus establish type relationships. While this can lead to a good design if approached carefully, detractors of\u2026","rel":"","context":"In &quot;C++&quot;","block_context":{"text":"C++","link":"https:\/\/www.rangakrish.com\/index.php\/category\/c\/"},"img":{"alt_text":"Rectangle and Circle Defined","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2025\/04\/cpp2-251x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=476"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/476\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}