Skip to content

Commit 97f791d

Browse files
committed
Update title and TOC entry to include tuples in anonymous types documentation
1 parent a8c8d9f commit 97f791d

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

docs/csharp/fundamentals/types/anonymous-types.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Anonymous Types"
2+
title: "Anonymous Types and Tuples"
33
description: Anonymous types in C# encapsulate a set of read-only properties in an object without having to explicitly define a type. The compiler generates a name.
44
ms.date: 10/13/2025
55
f1_keywords:
@@ -8,12 +8,11 @@ helpviewer_keywords:
88
- "anonymous types [C#]"
99
- "C# Language, anonymous types"
1010
---
11-
# Anonymous types
11+
# Anonymous types and tuples
1212

1313
Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first. The type name is generated by the compiler and isn't available at the source code level. The type of each property is inferred by the compiler.
1414

15-
> [!TIP]
16-
> In most scenarios, [tuples](../../language-reference/builtin-types/value-tuples.md) are the preferred choice over anonymous types. Tuples provide better performance, support deconstruction, and offer more flexible syntax. Use anonymous types primarily when you need expression tree support or when working with code that requires reference types.
15+
In most scenarios, [tuples](../../language-reference/builtin-types/value-tuples.md) are the preferred choice over anonymous types. Tuples provide better performance, support deconstruction, and offer more flexible syntax. Use anonymous types primarily when you need expression tree support or when working with code that requires reference types.
1716

1817
## Anonymous types vs tuples
1918

@@ -58,11 +57,11 @@ The most common scenario is to initialize an anonymous type with properties from
5857

5958
The anonymous type declaration starts with the [`new`](../../language-reference/operators/new-operator.md) operator together with an [object initializer](../../programming-guide/classes-and-structs/object-and-collection-initializers.md). The declaration initializes a new type that uses only two properties from `Product`. Anonymous types are typically used in the [`select`](../../language-reference/keywords/select-clause.md) clause of a query expression to return a smaller amount of data. For more information about queries, see [LINQ in C#](../../linq/index.md).
6059

61-
If you don't specify member names in the anonymous type, the compiler gives the anonymous type members the same name as the property being used to initialize them. You provide a name for a property that's being initialized with an expression, as shown in the previous example. In the following example, the names of the properties of the anonymous type are `Color` and `Price`. The instances are item from the `products` collection of `Product` types:
60+
If you don't specify member names in the anonymous type, the compiler gives the anonymous type members the same name as the property being used to initialize them. You provide a name for a property that's being initialized with an expression, as shown in the previous example.
6261

63-
:::code language="csharp" source="snippets/anonymous-types/Program.cs" ID="snippet81":::
62+
In the following example, the names of the properties of the anonymous type are `Color` and `Price`. The instances are item from the `products` collection of `Product` types:
6463

65-
Anonymous types contain one or more public read-only properties. No other kinds of class members, such as methods or events, are valid. The expression that is used to initialize a property can't be `null`, an anonymous function, or a pointer type.
64+
:::code language="csharp" source="snippets/anonymous-types/Program.cs" ID="snippet81":::
6665

6766
## Projection initializers with anonymous types
6867

docs/csharp/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ items:
5656
href: fundamentals/types/interfaces.md
5757
- name: Generics
5858
href: fundamentals/types/generics.md
59-
- name: Anonymous Types
59+
- name: Anonymous types and tuples
6060
href: fundamentals/types/anonymous-types.md
6161
# TODO: Delegates, lambdas and events
6262
- name: Object-oriented programming

0 commit comments

Comments
 (0)