Skip to content

Instantly share code, notes, and snippets.

@zHaytam
Last active July 3, 2020 09:01
Show Gist options
  • Save zHaytam/27eb7119d5fe35c3dda015a53e52bcaa to your computer and use it in GitHub Desktop.
Save zHaytam/27eb7119d5fe35c3dda015a53e52bcaa to your computer and use it in GitHub Desktop.
// Defining a record like this
public record Rectangle1 { double Width; double Height; }
// Is equivalent to this
public record Rectangle1
{
public double Width { get; init; }
public double Height { get; init; }
}
// Defining a record like this
public record Rectangle2(double Width, double Height);
// Is equivalent to this
public record Rectangle2
{
public double Width { get; init; }
public double Height { get; init; }
public Rectangle2(double width, double height)
=> (Width, Height) = (width, height);
public void Deconstruct(out double width, out double height)
=> (width, height) = (Width, Height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment