{"id":3315,"date":"2020-01-30T21:49:56","date_gmt":"2020-01-30T20:49:56","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=3315"},"modified":"2022-07-25T08:33:24","modified_gmt":"2022-07-25T07:33:24","slug":"c-valuetuple","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/c-valuetuple\/","title":{"rendered":"C# ValueTuple"},"content":{"rendered":"\n<p><a href=\"https:\/\/stackoverflow.com\/a\/44250573\">https:\/\/stackoverflow.com\/a\/44250573<\/a><\/p>\n\n\n\n<p>You are looking for a syntax like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">List&lt;(int, string)> list = new List&lt;(int, string)>();\nlist.Add((3, \"first\"));\nlist.Add((6, \"second\"));<\/pre>\n\n\n\n<p>You can use like that in your case:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">List&lt;(int, string)> Method() => \n    new List&lt;(int, string)>\n    {\n        (3, \"first\"),\n        (6, \"second\")\n    };<\/pre>\n\n\n\n<p>You can also name the values before returning:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">List&lt;(int Foo, string Bar)> Method() =>\n    ...<\/pre>\n\n\n\n<p>And you can receive the values while (re)naming them:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">List&lt;(int MyInteger, string MyString)> result = Method();\nvar firstTuple = result.First();\nint i = firstTuple.MyInteger;\nstring s = firstTuple.MyString;<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/stackoverflow.com\/a\/44250573 You are looking for a syntax like this: You can use like that in your case: You can also name the values before returning: And you can receive the values while (re)naming them:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[6,4,1],"tags":[],"class_list":["post-3315","post","type-post","status-publish","format-standard","hentry","category-dotnet","category-programming","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=3315"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3315\/revisions"}],"predecessor-version":[{"id":3316,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3315\/revisions\/3316"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=3315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=3315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=3315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}