Earn income with your C# skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

What is the best way to assign a C# auto-property an initial value.

For C# 6 and higher use they autoproperty initializer syntax.


class Person
{
    public Person()
    {
        // Assign initial value

        Name = "Johannes de Clerck";
    }
    public string Name { get; set; }
}

For C# 5 and below use the constructor to initialize the default value.


class Person
{
    public Person()
    {
        // Assign initial value

        Name = "Johannes de Clerck";
    }
    public string Name { get; set; }
}



Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas.      Vsn 1.3.0