C# 10 Quick Syntax Reference by Mikael Olsson

C# 10 Quick Syntax Reference by Mikael Olsson

Author:Mikael Olsson
Language: eng
Format: epub
ISBN: 9781484279816
Publisher: Apress


Two additional capabilities were added to auto-properties in C# 6. First, an initial value can be set as part of the declaration. Second, an autoproperty can be made read-only by leaving out the set accessor. Such a property can only be set in the constructor, or as part of the declaration, as shown here:class Time

{

// Read-only auto-property with initializer

public System.DateTime created { get; }

= System.DateTime.Now;

}

As of C# 9, the set accessor can be replaced by an init accessor to only allow the property to be set during the construction of the object. This accessor type is only allowed for instance properties and not for static properties.class Time

{

public int Seconds { get; init; }

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.