operatoroverload.cs

来自「vc的原码例子12 vc的原码例子12」· CS 代码 · 共 40 行

CS
40
字号
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 + =
减小字号Ctrl + -
显示快捷键?