c#入门经典(第三版) 练习6.8(4)
题目:修改下面的结构,使之包含一个返回订单总价格的函数。
struct order { public string itemName; public int unitCount; public double unitCost; }
代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace Test { class Program { struct order { public string itemName; public int unitCount; public double unitCost; public double Sum() { return unitCost * unitCount; } } static void Main(string[] args) { order ord; ord.unitCost = 100.45; ord.unitCount = 50; ord.itemName = "mp3"; Console.WriteLine(ord.Sum()); Console.ReadKey(); } } }
贯彻自己的思想