-
-
Save fatihdgn/4ee6f2c291d3066d03b9787ce454dc52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//You can have multiple return values using tuples new syntax. | |
(string hello, string world) GetHelloWorldMessage() | |
{ | |
// And create tuple with having your values in paranthesis. | |
return ("Hello", "World"); | |
} | |
//You can deconstruct the resulting tuples values and assing them to different variables like this. | |
var (h, w) = GetHelloWorldMessage(); | |
Console.Write($"{h} {w}"); | |
//You can also assing your variables with type declarations. | |
var (string h2, string w2) = GetHelloWorldMessage(); | |
Console.Write($"{h} {w}"); // This has the same output. | |
//Of course you can assing resulting tuple to a single tuple variable and use it like this. | |
var t = GetHelloWorldMessage(); | |
Console.Write($"{t.hello} {t.world}"); // This has the same output too. | |
// These tuples are actually using the new ValueTuple struct and this struct actually have the "ItemX" properties inside like the old tuple do. | |
// So you can use these properties too if you want. | |
Console.Write($"{t.Item1} {t.Item2}"); // Guess what, this has the same output. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment