Property initializers - CSharp Custom Type

CSharp examples for Custom Type:Property

Introduction

You can add a property initializer to automatic properties, just as with fields:

public decimal CurrentPrice { get; set; } = 123;

This gives CurrentPrice an initial value of 123.

Properties with an initializer can be read-only:

public int Maximum { get; } = 999;

Just as with read-only fields, read-only automatic properties can also be assigned in the type's constructor.


Related Tutorials