Skip to content
EntityQ2470517· pop 26· linked from 278 articles

Also known as struct, compound data, data record

composite data type; information block containing specific, identified fields

In the Vinony graph

Vinony's link graph records 278 inbound references to record, and connects out to Fortran, integer data type and punched card.

It sits within the topics Composite data types and Data types.

Vinony links it to 25 Wikipedia language editions.

Described at

Records - C# reference | Microsoft Learn

Learn about the record modifier for class and struct types in C#. Records provide standard support for value based equality on instances of record types.

learn.microsoft.com →

The record modifier provides built-in functionality for encapsulating data. The record class and record syntax define reference types . The record struct syntax defines a value type . The C language reference documents the most recently released version of the C language. It also contains initial documentation for features in public previews for the upcoming language release. The documentation identifies any feature first introduced in the last three versions of the language or in current public previews. When you declare a primary constructor on a record, the compiler generates public properties for the primary constructor parameters. The primary constructor parameters to a record are positional parameters . The compiler creates positional properties that mirror the primary constructor or positional parameters. The compiler doesn't synthesize properties for primary constructor parameters on types that don't have the record modifier. While records can be mutable, they're primarily intended for supporting immutable data models. The record type offers the following features: The remainder of this article discusses both record class and record struct types. The differences are detailed in each section. Decide between a record class and a record struct similar to deciding between a class and a struct . The term record describes behavior that applies to all record types. Either record struct or record class is used to describe behavior that applies to only struct or class types, respectively. A public automatically implemented property for each positional parameter provided in the record declaration. For record types and readonly record struct types: An init-only property. For record struct types: A read-write property. A primary constructor whose parameters match the positional parameters on the record declaration. For record struct types, a parameterless constructor that sets each field to its default value. A Deconstruct method with an out parameter for each positional parameter provided in the record declaration. The method deconstructs properties defined by using positional syntax; it ignores properties that are defined by using standard property syntax. You might want to add attributes to any of these elements the compiler creates from the record definition. You can add a target to any attribute you apply to the positional record's properties. The following example applies the System.Text.Json.Serialization.JsonPropertyNameAttribute to each property of the Person record. The property: target indicates that the attribute is applied to the compiler-generated property. Other values are field: to apply the attribute to the field, and param: to apply the attribute to the parameter. The preceding example also shows how to create XML documentation comments for the record. You can add the tag to add documentation for the primary constructor's parameters. If the generated automatically implemented property definition isn't what you want, define your own property or field of the same name. For example, you might want to change accessibility or mutability, or provide an implementation for either the get or set accessor. If you declare the member in your source, you must initialize it from the positional parameter of the record. If your property is an automatically implemented property, you must initialize the property. If you add a backing field in your source, you must initialize the backing field. The generated deconstructor uses your property or field definition. For instance, the following example declares the FirstName and LastName properties of a positional record public , but restricts the Id positional parameter to internal . You can use this syntax for records and record struct types. public static void Main() { Person person = new("Nancy", "Davolio", "12345"); Console.WriteLine(person.FirstName); //output: Nancy public static void Main() { Person person = new("Nancy", "Davolio", "12345"); Console.WriteLine(person.Fi

Excerpt from a page describing this subject · 39,795 chars · not written by Vinony

Wikidata facts

Part of
database
Has part
field
Show 6 more facts
Sources (1)

via Wikidata · CC0

Categories