Skip to content

Instantly share code, notes, and snippets.

@JohanLarsson
Last active December 4, 2018 06:17
Show Gist options
  • Save JohanLarsson/a44ebad3ef122a366c022e0747721928 to your computer and use it in GitHub Desktop.
Save JohanLarsson/a44ebad3ef122a366c022e0747721928 to your computer and use it in GitHub Desktop.
public struct Temperature : IEquatable<Temperature>
{
public Temperature(double celcius)
{
this.Celcius = celcius;
}
public double Celcius { get; }
public static bool operator ==(Temperature left, Temperature right)
{
return left.Equals(right);
}
public static bool operator !=(Temperature left, Temperature right)
{
return !left.Equals(right);
}
public bool Equals(Temperature other)
{
return this.Celcius.Equals(other.Celcius);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
return obj is Temperature && this.Equals((Temperature) obj);
}
public override int GetHashCode()
{
return this.Celcius.GetHashCode();
}
}
public class TemperatureChangedEventArgs : EventArgs
{
public TemperatureChangedEventArgs(Temperature temperature)
{
this.Temperature = temperature;
this.Time = DateTime.UtcNow;
}
public Temperature Temperature { get; }
public DateTime Time { get; }
}
public class TemperatureDevice
{
public event EventHandler<TemperatureChangedEventArgs> TemperatureChanged;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment