Skip to content

Commit b3d5585

Browse files
CopilotBillWagner
andcommitted
Clarify that collection expressions don't support inline arrays
Co-authored-by: BillWagner <[email protected]>
1 parent 5c38bf4 commit b3d5585

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

docs/csharp/language-reference/operators/collection-expressions.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The spread element `..vowels`, when evaluated, produces five elements: `"a"`, `"
3434
A *collection expression* can be converted to different collection types, including:
3535

3636
- <xref:System.Span%601?displayProperty=nameWithType> and <xref:System.ReadOnlySpan%601?displayProperty=nameWithType>.
37-
- [Arrays](../builtin-types/arrays.md).
37+
- [Arrays](../builtin-types/arrays.md), such as `int[]` or `string[]`.
3838
- Any type with a *create* method whose parameter type is `ReadOnlySpan<T>` where there's an implicit conversion from the collection expression type to `T`.
3939
- Any type that supports a [collection initializer](../../programming-guide/classes-and-structs/object-and-collection-initializers.md#collection-initializers), such as <xref:System.Collections.Generic.List%601?displayProperty=nameWithType>. Usually, this requirement means the type supports <xref:System.Collections.Generic.IEnumerable%601?displayProperty=nameWithType> and there's an accessible `Add` method to add items to the collection. There must be an implicit conversion from the collection expression elements' type to the collection's element type. For spread elements, there must be an implicit conversion from the spread element's type to the collection's element type.
4040
- Any of the following interfaces:
@@ -44,6 +44,9 @@ A *collection expression* can be converted to different collection types, includ
4444
- <xref:System.Collections.Generic.ICollection%601?displayProperty=fullName>.
4545
- <xref:System.Collections.Generic.IList%601?displayProperty=fullName>.
4646

47+
> [!NOTE]
48+
> Collection expressions cannot be used to initialize [inline arrays](../builtin-types/struct.md#inline-arrays). Inline arrays require different initialization syntax.
49+
4750
> [!IMPORTANT]
4851
> A collection expression always creates a collection that includes all elements in the collection expression, regardless of the target type of the conversion. For example, when the target of the conversion is <xref:System.Collections.Generic.IEnumerable%601?displayProperty=nameWithType>, the generated code evaluates the collection expression and stores the results in an in-memory collection.
4952
>

0 commit comments

Comments
 (0)