Skip to content

Instantly share code, notes, and snippets.

@fatihdgn
Last active September 30, 2018 15:33
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 fatihdgn/f8fd1077aaf6ab7fa12c3a92b68e9f85 to your computer and use it in GitHub Desktop.
Save fatihdgn/f8fd1077aaf6ab7fa12c3a92b68e9f85 to your computer and use it in GitHub Desktop.
public static class TupleExtensions
{
public static Point ToPoint(this (int x, int y) self) => new Point(x,y);
public static (int x, int y) => ToTuple(this Point self) => (self.X, self.Y);
}
// First, let's create a new point.
var p = new Point(10,20);
// And deconstruct it with converting it a tuple first with ToTuple extension method.
var (x,y) = p.ToTuple();
// At last, create a tuple using x and y variables and convert it to a point using ToPoint extension method.
var p2 = (x,y).ToPoint();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment