close
class ListInit
    {
        static void Main(string[] args)
        {
            // The demo of List Initialize Set including old declaration and new declaration(C#3.0)
            // Old initialization.
            List stringOld = new List();
            stringOld.Add("string_1");
            stringOld.Add("string_2");

            // New initialization.
            List stringNew = new List()
            {
                "string_1",
                "string_2"
            };

            // Combine Object and List Init.
            List list = new List{
                new Contact{
                    LastName = "Alen",
                    DateOfBirth = new DateTime(1234,1,13)
                },
                new Contact{
                    LastName = "AlenTwo",
                    DateOfBirth = new DateTime(2345,1,23)
                }
            };
        }

        private class Contact
        {
            public string LastName { get; set; }
            public DateTime DateOfBirth { get; set; }
        }
    }
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 imagefish 的頭像
    imagefish

    幻想魚的幻想空間

    imagefish 發表在 痞客邦 留言(0) 人氣()