结构函数的一个例子
struct order { public string itemName; public int unitCount; public double unitCost; public double SumCost() { return unitCount * unitCost; } public string OrderInformation() { return "Order information: " + unitCount + " " + itemName + " " + "item at $" + unitCost + " each, total cost $" + SumCost(); } } static void Main(string[] args) { order bill; bill.itemName = "Milk"; bill.unitCount = 10; bill.unitCost = 0.3; Console.WriteLine(bill.SumCost()); Console.WriteLine(bill.OrderInformation()); Console.ReadKey(); }
第6章练习题5
暧昧帖
Tags : c#
