⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hour.cs

📁 微软系列丛书<<C#2005从入门到精通>>
💻 CS
字号:

namespace Operators
{
	struct Hour
	{
		public Hour(int initialValue)
		{
			this.value = System.Math.Abs(initialValue) % 24;
		}

		public int Value
		{
			get { return this.value; }
		}

		public static bool operator==(Hour lhs, int rhs)
		{
			return lhs.value == rhs;
		}

		public static bool operator!=(Hour lhs, int rhs)
		{
			return lhs.value != rhs;
		}

		public static bool operator==(int lhs, Hour rhs)
		{
			return lhs == rhs.value;
		}

		public static bool operator!=(int lhs, Hour rhs)
		{
			return lhs != rhs.value;
		}

		public override bool Equals(object other)
		{
			return (other is Hour) && Equals((Hour)other);
		}

		public bool Equals(Hour other)
		{
			return this.value == other.value;
		}

		public override int GetHashCode()
		{
			return this.value;
		}

		public static Hour operator++(Hour arg)
		{
			arg.value++;
			if (arg.value == 24)
			{
				arg.value = 0;
			}
			return arg;
		}

		private int value;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -