c#入门经典(第三版) 练习6.8(5)

题目:在order结构中添加另一个函数,该结构返回一个格式化的字符串,以合适的值替换用尖括号括起来的斜体条目。

Order Information:<unit count> <item name> items at $<unit cost> each,total cost $<total cost>

代码:

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;
            }
            public string show() { 
                return "order Information:"+unitCount+itemName+"items at $"+unitCost+"each,total cost $"+Sum();
            }
        }

        static void Main(string[] args)
        {
            order ord;
            ord.unitCost = 100.45;
            ord.unitCount = 50;
            ord.itemName = "mp3";
            Console.WriteLine(ord.show());
            Console.ReadKey();
        }
    }
}
贯彻自己的思想
原文地址:https://www.cnblogs.com/593213556wuyubao/p/2754314.html