C# Builder

如下:

class Program
{
    static void Main(string[] args)
    {
        var a = new Class1.Builder().BuildA(1).BuildB(2.1).BuildUp();
        Console.Read();
    }
}
public class Class1
{
    private Class1(Builder builder)
    {
        A = builder.A;
        B = builder.B;
    }
    internal int A { get; set; }
    internal double B { get; set; }

    public class Builder
    {
        internal int A { get; set; }
        internal double B { get; set; }
        public Builder BuildA(int a)
        {
            A = a;
            return this;
        }
        public Builder BuildB(double b)
        {
            B = b;
            return this;
        }
        public Class1 BuildUp()
        {
            return new Class1(this);
        }
    }
}

 

posted on 2013-08-04 21:18  yao2yao4  阅读(196)  评论(0编辑  收藏  举报

导航