Required Keyword
05/21/2023
C# 11 introduces a new keyword: required
. This keyword can be applied onto fields or properties to make them required to be set during initialization. In this post I will focus on using required properties.
In the past developers could create init
properties that could be set only at initialization time by the type's constructor or object initializer. However, the compiler did not require the developer to explicitly set a value to a property.
Required properties make object initializers issue a compiler error when the developer does not set a required property.
In this post I will explore the following topics for required properties: