Skip to content

Instantly share code, notes, and snippets.

@lgolubyev
Created July 26, 2022 11:19
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 lgolubyev/b9aef8049734f2d62ddb0c5b91c5b4d1 to your computer and use it in GitHub Desktop.
Save lgolubyev/b9aef8049734f2d62ddb0c5b91c5b4d1 to your computer and use it in GitHub Desktop.
public readonly struct Measurement
{
public Measurement()
{
Value = double.NaN;
Description = "Undefined";
}
public Measurement(double value, string description)
{
Value = value;
Description = description;
}
public double Value { get; init; }
public string Description { get; init; }
public override string ToString() => $"{Value} ({Description})";
}
public static void Main()
{
var m1 = new Measurement();
Console.WriteLine(m1); // output: NaN (Undefined)
var m2 = default(Measurement);
Console.WriteLine(m2); // output: 0 ()
var ms = new Measurement[2];
Console.WriteLine(string.Join(", ", ms)); // output: 0 (), 0 ()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment