Skip to content

Instantly share code, notes, and snippets.

@curegit
Created October 20, 2021 04:58
Show Gist options
  • Save curegit/13e74749a1aa0b3ce1740979263b3099 to your computer and use it in GitHub Desktop.
Save curegit/13e74749a1aa0b3ce1740979263b3099 to your computer and use it in GitHub Desktop.
C# でのユニット型実装
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