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

📄 operatoroverload.cs

📁 vc的原码例子12 vc的原码例子12
💻 CS
字号:
class clsItem
{
	public clsItem(string text, double price)
	{
		Item = text;
		Price = price;
	}

	static public double operator +(clsItem x, clsItem y)
	{
		return(x.Price + y.Price);
	} 

	public void ShowItem()
	{
		System.Console.WriteLine("{0} ${1}", Item, Price);
	}

	private string Item;
	private double Price;
};




class clsOperatorOverload
{
	static void Main()
	{
		clsItem Purse = new clsItem("Hand bag", 25.00);
		clsItem Shoes = new clsItem("Loafers", 75.00);

		Purse.ShowItem();
		Shoes.ShowItem();
		System.Console.WriteLine("Total cost ${0}",
			Purse + Shoes);
	}
}

⌨️ 快捷键说明

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