-
-
Save richlander/17d7455573b14ef88a6b957e1e21c271 to your computer and use it in GitHub Desktop.
Record with static helper
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
using System; | |
var weight = 200; | |
WeightMeasurement measurement = new(DateTime.Now, weight) | |
{ | |
Pounds = WeightMeasurement.GetPounds(weight) | |
}; | |
Console.WriteLine(measurement); | |
public record WeightMeasurement(DateTime Date, double Kilograms) | |
{ | |
public double Pounds {get; init;} | |
public static double GetPounds(double kilograms) => kilograms * 2.20462262; | |
} |
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net5.0</TargetFramework> | |
<Nullable>Enable</Nullable> | |
</PropertyGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment