Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created October 17, 2018 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/46da0cfb940f6362b6dbec908b0eef46 to your computer and use it in GitHub Desktop.
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
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