{"id":20490250,"url":"https://github.com/juniormayhe/csharp7tuples","last_synced_at":"2025-07-16T03:45:25.888Z","repository":{"id":115727442,"uuid":"95158335","full_name":"juniormayhe/CSharp7Tuples","owner":"juniormayhe","description":"Sample of C# 7.0 new System.ValueTuple feature","archived":false,"fork":false,"pushed_at":"2017-06-22T23:03:15.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-05T17:23:11.455Z","etag":null,"topics":["csharp","dotnet","tuple","tuples"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juniormayhe.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-22T21:32:50.000Z","updated_at":"2017-07-01T03:01:24.000Z","dependencies_parsed_at":"2023-07-04T18:19:21.417Z","dependency_job_id":null,"html_url":"https://github.com/juniormayhe/CSharp7Tuples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/juniormayhe/CSharp7Tuples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juniormayhe%2FCSharp7Tuples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juniormayhe%2FCSharp7Tuples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juniormayhe%2FCSharp7Tuples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juniormayhe%2FCSharp7Tuples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juniormayhe","download_url":"https://codeload.github.com/juniormayhe/CSharp7Tuples/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juniormayhe%2FCSharp7Tuples/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265479825,"owners_count":23773621,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","tuple","tuples"],"created_at":"2024-11-15T17:16:18.370Z","updated_at":"2025-07-16T03:45:25.846Z","avatar_url":"https://github.com/juniormayhe.png","language":"C#","readme":"## C# 7.0 Tuples ##\n\nSince C# 4.0 tuples has allowed us to return multiple results without the need to create a custom class or specify out and ref parameters. C# 7.0 brings new syntax.\n\n### Get me to the sample\n\nHere's a quick sample of Tuple's new syntax in C# 7.0. \n\n\u003e **Note:** In projects older that 4.6 you will need to install System.ValueTuple on Nuget Manager:\n\n```\n//if it is not intended to make this method static, you should move it to \n//the same level where it is being called.\n(int sum, int count) calculate(int[] values)\n{\n\t//Create tuple items \"sum\" and \"count\" \n\t//and assign both items with 0 as default value\n\tvar tuple = (sum: 0, count: 0);\n\n\t//loop int array\n\tforeach (var v in values)\n\t{\n\t\t//you can assign directly a tuple with sum and count calculations\n\t\t//tuple = (tuple.sum + v, tuple.count + 1);\n\n\t\t//or you can use a local function\n\t\tSumAndCount(v, 1);\n\t}\n\t\n\t//return tuple with final results\n\treturn tuple;\n\n\t//creates a local function for sum\n\tvoid SumAndCount(int sum, int count)\n\t{\n\t\tConsole.WriteLine($\"Using SumAndCount(int {sum}, int {count}) local function...\");\n\t\ttuple.sum += sum;\n\t\ttuple.count += count;\n\t}\n}//calculate\n```\n\nIn the same context you may use `calculate` method as follows:\n\n```\n//declare your array with dummy data\nint[] numbers = { 10, 20, 30, 40, 50 };\n\n//deconstruct tuple\nvar (sum, count) = calculate(numbers);\n\nConsole.WriteLine(\"C# 7.0 Tuples sample. Don't forget to add in nuget System.ValueType library!\\n\");\nConsole.WriteLine($\"We'll compute Sum and Count of these numbers: {String.Join(\",\",numbers)}:\\n\");\n\nConsole.WriteLine($\"-\u003e Sum is {sum} and the Count is {count}\\n\");\nConsole.WriteLine(\"Press any key to continue...\");\nConsole.ReadKey();\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuniormayhe%2Fcsharp7tuples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuniormayhe%2Fcsharp7tuples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuniormayhe%2Fcsharp7tuples/lists"}