Created
July 26, 2022 11:19
-
-
Save lgolubyev/b9aef8049734f2d62ddb0c5b91c5b4d1 to your computer and use it in GitHub Desktop.
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
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