C#初始化器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            a ee = new a() { a1 = "第一个",a2 = "第二个", a3 = "第三个" };

            a tt = new a("哈哈1") { a2 = "哈哈2", a3 = "哈哈3" };

            Console.WriteLine("{0}{1}{2}",ee.a1,ee.a2,ee.a3);
            Console.WriteLine("{0}{1}{2}", tt.a1, tt.a2, tt.a3);
        }
    }


    class a
    {
        public  string a1{get; set;}
        public string a2 { get; set; }
        public string a3 { get; set; }

        public a(string dd)
        {
            this.a1 = dd;
        }

        public a()
        {
            
        }
    }
}

输出:

第一个第二个第三个
哈哈1哈哈2哈哈3

posted @ 2017-09-10 13:43  巫居树  阅读(1079)  评论(0编辑  收藏  举报