What is the positional syntax for property definition in C# 9.0?

Records in C# 9.0 provide positional syntax to declare and initialize property values of an instance.

The compiler makes the properties public init-only auto-implemented when the user employs positional syntax to declare and initialize properties.

The compiler also creates a constructor that accepts values and assigns them to properties according to their position. Additionally, a deconstruct method with an out parameter for each positional parameter is created when there are more than two positional properties.

Example

The following example demonstrates how to use the positional syntax for property definition with C# 9.0 records.

Example 1

The following code creates a record Course and initializes the init-only properties without an explicit constructor, using the positional syntax.

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

Output

Course { Name = Intro to programming, Price = 35 }

Example 2

If the user does not want the auto-implemented property definition, they can define the property themselves. The constructor and deconstructor then utilize the user’s property definition. The following example sets the Name property as protected instead of public.

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

Output

Course { Price = 35 }

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved