C#对象初始或器-Chapter3 P38

  protected string GetMessage()
        {
            //如何构造和初始化泛型集合库中的一个数组和两个类。
            Product myProduct = new Product{ProductID=100,Name="Kayak",Description ="A boat for one person",Price=275M,Category="Watersports"};
            return String.Format("Category:{0}", myProduct.Category);
            string[] stringArray = { "apple", "orange", "plum" };
            List<int> intList = new List<int> { 10, 20, 30, 40 };
            Dictionary<string, int> myDict = new Dictionary<string, int> { { "apple", 10 }, { "orange", 20 }, { "plum", 30 } };
            return String.Format("fruit:{0}", (object)stringArray[1]);
        }
原文地址:https://www.cnblogs.com/CandiceW/p/4900580.html