Created
October 17, 2018 17:35
-
-
Save guitarrapc/46da0cfb940f6362b6dbec908b0eef46 to your computer and use it in GitHub Desktop.
C# could not deconstruct and pass value in inline. Go can do it. https://gist.github.com/guitarrapc/e39df708d99abf3619fc73becbf714c2
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
void Main() | |
{ | |
var p = Pair(10).Dump(); | |
// 直接はdeconstructされてないのでダメ | |
Add(p).Dump(); | |
// 当然 valuetuple でウケルならいいけどそうじゃない | |
Add2(p).Dump(); | |
Add2(Pair(10)).Dump(); | |
// deconstruct して個別に渡すなら当然okだけどそうじゃない | |
(var x, var y) = Pair(10); | |
Add(x, y).Dump(); | |
// 直接インラインでdeconstruct構文はだめ、かつこれだと (x2, y2) のvalue tuple を渡すことになる | |
Add((var x2, var y2) = Pair(10)).Dump(); | |
} | |
// Define other methods and classes here | |
(int, int) Pair(int x) | |
{ | |
return (x, x + 1); | |
} | |
int Add(int x, int y) | |
{ | |
return x + y; | |
} | |
int Add2((int x, int y) value) | |
{ | |
return value.x + value.y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment