通过结构体来实现,格式化输出字符串,简单理解结构体的方便之处,分享:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication8 { class Program { struct order { public string itemName; public int unitCount; public double unitCost; public double TotalCost() { return unitCount * unitCost; } public string Info() { return "Order information :" + unitCount.ToString() + " " + itemName + " items at $ " + unitCost.ToString() + " each , total cost $ " + TotalCost().ToString(); } } static void Main(string[] args) { order myOrder; myOrder.itemName = "TestStruct"; myOrder.unitCount = 3; myOrder.unitCost = 2.1; Console.WriteLine("通过结构体来格式输出:{0}" , myOrder .Info () ); } } }