Skip to content

Commit 483cb89

Browse files
committed
Add first class span types
Add updates to C# 14 for the First class Span types.
1 parent b519187 commit 483cb89

File tree

14 files changed

+146
-123
lines changed

14 files changed

+146
-123
lines changed

docfx.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
"csharp-11.0/*.md",
5555
"csharp-12.0/*.md",
5656
"csharp-13.0/*.md",
57-
"field-keyword.md"
57+
"field-keyword.md",
58+
"unbound-generic-types-in-nameof.md",
59+
"first-class-span-types.md"
5860
],
5961
"src": "_csharplang/proposals",
6062
"dest": "csharp/language-reference/proposals",
@@ -679,6 +681,8 @@
679681
"_csharplang/proposals/csharp-13.0/partial-properties.md": "All partial properties and indexers",
680682
"_csharplang/proposals/csharp-13.0/overload-resolution-priority.md": "Overload resolution priority tiebreaker attribute",
681683
"_csharplang/proposals/field-keyword.md": "The `field` contextual keyword",
684+
"_csharplang/proposals/unbound-generic-types-in-nameof.md": "Unbound generic types in `nameof`",
685+
"_csharplang/proposals/first-class-span-types.md": "First-class span types",
682686
"_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md": "C# compiler breaking changes since C# 10",
683687
"_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 8.md": "C# compiler breaking changes since C# 11",
684688
"_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 9.md": "C# compiler breaking changes since C# 12",
@@ -800,6 +804,8 @@
800804
"_csharplang/proposals/csharp-13.0/partial-properties.md": "This proposal provides for partial properties and indexers, allowing the definition of a property or indexer to be split across multiple parts.",
801805
"_csharplang/proposals/csharp-13.0/overload-resolution-priority.md": "This proposal introduces a new attribute, `OverloadResolutionPriorityAttribute`, that can be applied to methods to influence overload resolution.",
802806
"_csharplang/proposals/field-keyword.md": "This proposal introduces a new keyword, `field`, that accesses the compiler generated backing field in a property accessor.",
807+
"_csharplang/proposals/unbound-generic-types-in-nameof.md": "This proposal introduces the ability to use unbound generic types such as `List<>` in `nameof` expressions. The type argument isn't required.",
808+
"_csharplang/proposals/first-class-span-types.md": "This proposal provides several implicit conversions to `Span<T>` and `ReadOnlySpan<T>` that enable library authors to have fewer overloads and developers to write code that resolves to faster Span based APIs",
803809
"_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md": "Learn about any breaking changes since the initial release of C# 10 and included in C# 11",
804810
"_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 8.md": "Learn about any breaking changes since the initial release of C# 11 and included in C# 12",
805811
"_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 9.md": "Learn about any breaking changes since the initial release of C# 12 and included in C# 13",

docs/csharp/language-reference/builtin-types/built-in-types.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Built-in types"
33
description: "Learn C# built-in value and reference types"
4-
ms.date: 03/15/2021
4+
ms.date: 02/04/2025
55
helpviewer_keywords:
66
- "types [C#], built-in"
77
- "built-in C# types"
@@ -36,7 +36,7 @@ The following table lists the C# built-in [reference](../keywords/reference-type
3636
|[`string`](reference-types.md#the-string-type)|<xref:System.String?displayProperty=nameWithType>|
3737
|[`dynamic`](reference-types.md#the-dynamic-type)|<xref:System.Object?displayProperty=nameWithType>|
3838

39-
In the preceding tables, each C# type keyword from the left column (except [dynamic](reference-types.md#the-dynamic-type)) is an alias for the corresponding .NET type. They are interchangeable. For example, the following declarations declare variables of the same type:
39+
In the preceding tables, each C# type keyword from the left column (except [dynamic](reference-types.md#the-dynamic-type)) is an alias for the corresponding .NET type. They're interchangeable. For example, the following declarations declare variables of the same type:
4040

4141
```csharp
4242
int a = 123;
@@ -45,6 +45,16 @@ System.Int32 b = 123;
4545

4646
The [`void`](void.md) keyword represents the absence of a type. You use it as the return type of a method that doesn't return a value.
4747

48+
The C# language includes specialized rules for the <xref:System.Span`1?displayProperty=fullName> and <xref:System.ReadOnlySpan`1?displayProperty=fullName> types. These types aren't classified as built-in types, because there aren't C# keywords that correspond to these types. The C# language defines implicit conversions from array types and the string type to `Span<T>` and `ReadOnlySpan<T>`. These conversions integrate `Span` types into more natural programming scenarios. The following conversions are defined as *implicit span conversions*:
49+
50+
- From any single-dimensional array with element type `E` to `System.Span<E>`
51+
- From any single-dimensional with element type `E` to `System.ReadOnlySpan<U>`, when `E` has covariance conversion or an identity conversion to `U`
52+
- From `System.Span<E>` to `System.ReadOnlySpan<U>`, when `E` has a covariance conversion or an identity conversion to `U`
53+
- From `System.ReadOnlySpan<E>` to `System.ReadOnlySpan<U>`, when `E` has a covariance conversion or an identity conversion to `U`
54+
- From `string` to `System.ReadOnlySpan<char>`
55+
56+
The compiler never ignores any user defined conversion where an applicable *implicit span conversion* exists. Implicit span conversions can be applied to the first argument of [extension methods](../../programming-guide/classes-and-structs/extension-methods.md), the parameter with the `this` modifier. Implicit span conversions aren't considered for method group conversions.
57+
4858
## See also
4959

5060
- [Use language keywords instead of framework type names (style rule IDE0049)](../../../fundamentals/code-analysis/style-rules/ide0049.md)

docs/csharp/language-reference/builtin-types/collections.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: "Collections"
33
description: Learn about collections in C#, which are used to work with groups of objects. Collections have different characteristics regarding adding and removing elements, modifying elements, and enumerating the collection elements.
4-
ms.date: 08/22/2023
4+
ms.date: 02/04/2025
55
---
66
# Collections
77

8-
The .NET runtime provides many collection types that store and manage groups of related objects. Some of the collection types, such as <xref:System.Array?displayProperty=nameWithType>, <xref:System.Span%601?displayProperty=nameWithType>, and <xref:System.Memory%601?displayProperty=nameWithType> are recognized in the C# language. In addition, interfaces like <xref:System.Collections.Generic.IEnumerable%601?displayProperty=nameWithType> are recognized in the language for enumerating the elements of a collection.
8+
The .NET runtime provides many collection types that store and manage groups of related objects. Some of the collection types, such as <xref:System.Array?displayProperty=nameWithType>, <xref:System.Span%601?displayProperty=nameWithType>, and <xref:System.Memory%601?displayProperty=nameWithType> are recognized [in the C# language](./built-in-types.md). In addition, interfaces like <xref:System.Collections.Generic.IEnumerable%601?displayProperty=nameWithType> are recognized in the language for enumerating the elements of a collection.
99

1010
Collections provide a flexible way to work with groups of objects. You can classify different collections by these characteristics:
1111

docs/csharp/language-reference/operators/patterns.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Patterns - Pattern matching using the is and switch expressions."
33
description: "Learn about the patterns supported by the `is` and `switch` expressions. Combine multiple patterns using the `and`, `or`, and `not` operators."
4-
ms.date: 11/22/2024
4+
ms.date: 02/04/2025
55
f1_keywords:
66
- "and_CSharpKeyword"
77
- "or_CSharpKeyword"
@@ -48,15 +48,11 @@ You use declaration and type patterns to check if the run-time type of an expres
4848
A *declaration pattern* with type `T` matches an expression when an expression result is non-null and any of the following conditions are true:
4949

5050
- The run-time type of an expression result is `T`.
51-
51+
- The type `T` is a `ref struct` type and there is an identity conversion from the expression to `T`.
5252
- The run-time type of an expression result derives from type `T`, implements interface `T`, or another [implicit reference conversion](~/_csharpstandard/standard/conversions.md#1028-implicit-reference-conversions) exists from it to `T`. The following example demonstrates two cases when this condition is true:
53-
5453
:::code language="csharp" source="snippets/patterns/DeclarationAndTypePatterns.cs" id="ReferenceConversion":::
55-
5654
In the preceding example, at the first call to the `GetSourceLabel` method, the first pattern matches an argument value because the argument's run-time type `int[]` derives from the <xref:System.Array> type. At the second call to the `GetSourceLabel` method, the argument's run-time type <xref:System.Collections.Generic.List%601> doesn't derive from the <xref:System.Array> type but implements the <xref:System.Collections.Generic.ICollection%601> interface.
57-
5855
- The run-time type of an expression result is a [nullable value type](../builtin-types/nullable-value-types.md) with the underlying type `T`.
59-
6056
- A [boxing](../../programming-guide/types/boxing-and-unboxing.md#boxing) or [unboxing](../../programming-guide/types/boxing-and-unboxing.md#unboxing) conversion exists from the run-time type of an expression result to type `T`.
6157

6258
The following example demonstrates the last two conditions:

0 commit comments

Comments
 (0)