Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@S0und
Created January 16, 2020 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save S0und/470ada70474920dc6ed0981da7b0c8d0 to your computer and use it in GitHub Desktop.
Save S0und/470ada70474920dc6ed0981da7b0c8d0 to your computer and use it in GitHub Desktop.
Java like "static" builder pattern for c#
public class Person
{
public string Name { get; private set; }
public int Age { get; private set; }
private Person(Builder builder)
{
Name = builder.name;
Age = builder.age;
}
public sealed class Builder
{
internal string name;
internal int age;
public Builder Name(string name)
{
this.name = name;
return this;
}
public Builder Age(int age)
{
this.age = age;
return this;
}
public Person build()
{
return new Person(this);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment