Created
October 20, 2021 04:58
-
-
Save curegit/13e74749a1aa0b3ce1740979263b3099 to your computer and use it in GitHub Desktop.
C# でのユニット型実装
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; | |
using System.Diagnostics.CodeAnalysis; | |
[Serializable] | |
public struct Unit : IEquatable<Unit>, IComparable, IComparable<Unit> | |
{ | |
public override bool Equals([NotNullWhen(true)] object? obj) | |
{ | |
return obj is Unit; | |
} | |
public bool Equals(Unit other) | |
{ | |
return true; | |
} | |
int IComparable.CompareTo(object? other) | |
{ | |
if (other is null) | |
{ | |
return 1; | |
} | |
else if (other is not Unit) | |
{ | |
throw new ArgumentException(null, nameof(other)); | |
} | |
else | |
{ | |
return 0; | |
} | |
} | |
public int CompareTo(Unit other) | |
{ | |
return 0; | |
} | |
public override int GetHashCode() | |
{ | |
return 0; | |
} | |
public override string ToString() | |
{ | |
return "()"; | |
} | |
public static bool operator ==(Unit left, Unit right) | |
{ | |
return true; | |
} | |
public static bool operator !=(Unit left, Unit right) | |
{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment