diff --git a/.openpublishing.redirection.csharp.json b/.openpublishing.redirection.csharp.json index 81dce85972a07..de3bf14f0c23c 100644 --- a/.openpublishing.redirection.csharp.json +++ b/.openpublishing.redirection.csharp.json @@ -778,7 +778,7 @@ }, { "source_path_from_root": "/docs/csharp/language-reference/keywords/as.md", - "redirect_url": "/dotnet/csharp/language-reference/operators/type-testing-and-cast#as-operator" + "redirect_url": "/dotnet/csharp/language-reference/operators/type-testing-and-cast#the-as-operator" }, { "source_path_from_root": "/docs/csharp/language-reference/keywords/await.md", @@ -1075,7 +1075,7 @@ }, { "source_path_from_root": "/docs/csharp/language-reference/keywords/typeof.md", - "redirect_url": "/dotnet/csharp/language-reference/operators/type-testing-and-cast#typeof-operator" + "redirect_url": "/dotnet/csharp/language-reference/operators/type-testing-and-cast#the-typeof-operator" }, { "source_path_from_root": "/docs/csharp/language-reference/keywords/types.md", diff --git a/docs/csharp/fundamentals/tutorials/safely-cast-using-pattern-matching-is-and-as-operators.md b/docs/csharp/fundamentals/tutorials/safely-cast-using-pattern-matching-is-and-as-operators.md index ccfac9b081586..3ca501163156e 100644 --- a/docs/csharp/fundamentals/tutorials/safely-cast-using-pattern-matching-is-and-as-operators.md +++ b/docs/csharp/fundamentals/tutorials/safely-cast-using-pattern-matching-is-and-as-operators.md @@ -9,13 +9,13 @@ helpviewer_keywords: --- # How to safely cast by using pattern matching and the is and as operators -Because objects are polymorphic, it's possible for a variable of a base class type to hold a derived [type](../types/index.md). To access the derived type's instance members, it's necessary to [cast](../../programming-guide/types/casting-and-type-conversions.md) the value back to the derived type. However, a cast creates the risk of throwing an . C# provides [pattern matching](../functional/pattern-matching.md) statements that perform a cast conditionally only when it will succeed. C# also provides the [is](../../language-reference/operators/type-testing-and-cast.md#is-operator) and [as](../../language-reference/operators/type-testing-and-cast.md#as-operator) operators to test if a value is of a certain type. +Because objects are polymorphic, it's possible for a variable of a base class type to hold a derived [type](../types/index.md). To access the derived type's instance members, it's necessary to [cast](../../programming-guide/types/casting-and-type-conversions.md) the value back to the derived type. However, a cast creates the risk of throwing an . C# provides [pattern matching](../functional/pattern-matching.md) statements that perform a cast conditionally only when it will succeed. C# also provides the [is](../../language-reference/operators/type-testing-and-cast.md#the-is-operator) and [as](../../language-reference/operators/type-testing-and-cast.md#the-as-operator) operators to test if a value is of a certain type. The following example shows how to use the pattern matching `is` statement: :::code language="csharp" source="./snippets/safelycast/patternmatching/Program.cs" ID="PatternMatchingIs"::: -The preceding sample demonstrates a few features of pattern matching syntax. The `if (a is Mammal m)` statement combines the test with an initialization assignment. The assignment occurs only when the test succeeds. The variable `m` is only in scope in the embedded `if` statement where it has been assigned. You can't access `m` later in the same method. The preceding example also shows how to use the [`as` operator](../../language-reference/operators/type-testing-and-cast.md#as-operator) to convert an object to a specified type. +The preceding sample demonstrates a few features of pattern matching syntax. The `if (a is Mammal m)` statement combines the test with an initialization assignment. The assignment occurs only when the test succeeds. The variable `m` is only in scope in the embedded `if` statement where it has been assigned. You can't access `m` later in the same method. The preceding example also shows how to use the [`as` operator](../../language-reference/operators/type-testing-and-cast.md#the-as-operator) to convert an object to a specified type. You can also use the same syntax for testing if a [nullable value type](../../language-reference/builtin-types/nullable-value-types.md) has a value, as shown in the following example: diff --git a/docs/csharp/language-reference/builtin-types/nullable-value-types.md b/docs/csharp/language-reference/builtin-types/nullable-value-types.md index 323eff25986ff..b5feac649fd2f 100644 --- a/docs/csharp/language-reference/builtin-types/nullable-value-types.md +++ b/docs/csharp/language-reference/builtin-types/nullable-value-types.md @@ -96,17 +96,17 @@ The following example shows how to determine whether a instance. +As the example shows, you use the [typeof](../operators/type-testing-and-cast.md#the-typeof-operator) operator to create a instance. If you want to determine whether an instance is of a nullable value type, don't use the method to get a instance to be tested with the preceding code. When you call the method on an instance of a nullable value type, the instance is [boxed](#boxing-and-unboxing) to . As boxing of a non-null instance of a nullable value type is equivalent to boxing of a value of the underlying type, returns a instance that represents the underlying type of a nullable value type: [!code-csharp-interactive[GetType example](snippets/shared/NullableValueTypes.cs#GetType)] -Also, don't use the [is](../operators/type-testing-and-cast.md#is-operator) operator to determine whether an instance is of a nullable value type. As the following example shows, you cannot distinguish types of a nullable value type instance and its underlying type instance with the `is` operator: +Also, don't use the [is](../operators/type-testing-and-cast.md#the-is-operator) operator to determine whether an instance is of a nullable value type. As the following example shows, you cannot distinguish types of a nullable value type instance and its underlying type instance with the `is` operator: [!code-csharp-interactive[is operator example](snippets/shared/NullableValueTypes.cs#IsOperator)] -Instead use the from the first example and [typeof](../operators/type-testing-and-cast.md#typeof-operator) operator to check if an instance is of a nullable value type. +Instead use the from the first example and [typeof](../operators/type-testing-and-cast.md#the-typeof-operator) operator to check if an instance is of a nullable value type. > [!NOTE] > The methods described in this section are not applicable in the case of [nullable reference types](nullable-reference-types.md). diff --git a/docs/csharp/language-reference/compiler-messages/assembly-references.md b/docs/csharp/language-reference/compiler-messages/assembly-references.md index 6461228fc8794..a19067f8af1c0 100644 --- a/docs/csharp/language-reference/compiler-messages/assembly-references.md +++ b/docs/csharp/language-reference/compiler-messages/assembly-references.md @@ -81,7 +81,7 @@ These compiler errors indicate one of these problems in your code: - The project doesn't reference the required assembly. To fix this error, [add a reference to the required assembly](../../../standard/assembly/index.md#add-a-reference-to-an-assembly). - You misspelled the name of a type. Check the name of the type. -- You used a variable name where the name of a was expected, such as in the [`typeof` operator](../operators/type-testing-and-cast.md#typeof-operator) or the [`is` operator](../operators/type-testing-and-cast.md#is-operator). +- You used a variable name where the name of a was expected, such as in the [`typeof` operator](../operators/type-testing-and-cast.md#the-typeof-operator) or the [`is` operator](../operators/type-testing-and-cast.md#the-is-operator). - You used the [global scope operator, (`::`)](../operators/namespace-alias-qualifier.md) when the type isn't in the global namespace. ## Type forwarding diff --git a/docs/csharp/language-reference/compiler-messages/cs0039.md b/docs/csharp/language-reference/compiler-messages/cs0039.md index cf168926849de..6ce49e440313b 100644 --- a/docs/csharp/language-reference/compiler-messages/cs0039.md +++ b/docs/csharp/language-reference/compiler-messages/cs0039.md @@ -12,7 +12,7 @@ ms.assetid: f9fcb1c5-4ea4-41f3-826e-9ab0ac43dd3e Cannot convert type 'type1' to 'type2' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion -A conversion with the [as](../operators/type-testing-and-cast.md#as-operator) operator is allowed by inheritance, reference conversions, and boxing conversions. +A conversion with the [as](../operators/type-testing-and-cast.md#the-as-operator) operator is allowed by inheritance, reference conversions, and boxing conversions. ## Example diff --git a/docs/csharp/language-reference/compiler-messages/cs0413.md b/docs/csharp/language-reference/compiler-messages/cs0413.md index 59e47582fa75d..0896efebfcc21 100644 --- a/docs/csharp/language-reference/compiler-messages/cs0413.md +++ b/docs/csharp/language-reference/compiler-messages/cs0413.md @@ -12,7 +12,7 @@ ms.assetid: a01bd1ec-015b-433b-be55-b91db268d6a5 The type parameter 'type parameter' cannot be used with the 'as' operator because it does not have a class type constraint nor a 'class' constraint -This error occurs if a generic type uses the [as](../operators/type-testing-and-cast.md#as-operator) operator, but that generic type does not have a class type constraint. The `as` operator is only allowed with reference and nullable value types, so the type parameter must be constrained to guarantee that it is not a value type. To avoid this error, use a class type constraint or a reference type constraint. +This error occurs if a generic type uses the [as](../operators/type-testing-and-cast.md#the-as-operator) operator, but that generic type does not have a class type constraint. The `as` operator is only allowed with reference and nullable value types, so the type parameter must be constrained to guarantee that it is not a value type. To avoid this error, use a class type constraint or a reference type constraint. This is because the `as` operator could return `null`, which is not a possible value for a value type, and the type parameter must be treated as a value type unless it is a class type constraint or a reference type constraint. diff --git a/docs/csharp/language-reference/keywords/index.md b/docs/csharp/language-reference/keywords/index.md index 4f7d06539e43f..8cd1a66953ff2 100644 --- a/docs/csharp/language-reference/keywords/index.md +++ b/docs/csharp/language-reference/keywords/index.md @@ -20,7 +20,7 @@ The first table in this article lists keywords that are reserved identifiers in :::row::: :::column::: [`abstract`](abstract.md) - [`as`](../operators/type-testing-and-cast.md#as-operator) + [`as`](../operators/type-testing-and-cast.md#the-as-operator) [`base`](base.md) [`bool`](../builtin-types/bool.md) [`break`](../statements/jump-statements.md#the-break-statement) @@ -91,7 +91,7 @@ The first table in this article lists keywords that are reserved identifiers in [`throw`](../statements/exception-handling-statements.md#the-throw-statement) [`true`](../builtin-types/bool.md) [`try`](../statements/exception-handling-statements.md#the-try-statement) - [`typeof`](../operators/type-testing-and-cast.md#typeof-operator) + [`typeof`](../operators/type-testing-and-cast.md#the-typeof-operator) [`uint`](../builtin-types/integral-numeric-types.md) [`ulong`](../builtin-types/integral-numeric-types.md) [`unchecked`](../statements/checked-and-unchecked.md) diff --git a/docs/csharp/language-reference/operators/index.md b/docs/csharp/language-reference/operators/index.md index b4f36f0695dfc..3b83d5cf12849 100644 --- a/docs/csharp/language-reference/operators/index.md +++ b/docs/csharp/language-reference/operators/index.md @@ -70,14 +70,14 @@ The following table lists the C# operators starting with the highest precedence | Operators | Category or name | | --------- | ---------------- | -| [x.y](member-access-operators.md#member-access-expression-), [f(x)](member-access-operators.md#invocation-expression-), [a[i]](member-access-operators.md#indexer-operator-), [`x?.y`](member-access-operators.md#null-conditional-operators--and-), [`x?[y]`](member-access-operators.md#null-conditional-operators--and-), [x++](arithmetic-operators.md#increment-operator-), [x--](arithmetic-operators.md#decrement-operator---), [x!](null-forgiving.md), [new](new-operator.md), [typeof](type-testing-and-cast.md#typeof-operator), [checked](../statements/checked-and-unchecked.md), [unchecked](../statements/checked-and-unchecked.md), [default](default.md), [nameof](nameof.md), [delegate](delegate-operator.md), [sizeof](sizeof.md), [stackalloc](stackalloc.md), [x->y](pointer-related-operators.md#pointer-member-access-operator--) | Primary | +| [x.y](member-access-operators.md#member-access-expression-), [f(x)](member-access-operators.md#invocation-expression-), [a[i]](member-access-operators.md#indexer-operator-), [`x?.y`](member-access-operators.md#null-conditional-operators--and-), [`x?[y]`](member-access-operators.md#null-conditional-operators--and-), [x++](arithmetic-operators.md#increment-operator-), [x--](arithmetic-operators.md#decrement-operator---), [x!](null-forgiving.md), [new](new-operator.md), [typeof](type-testing-and-cast.md#the-typeof-operator), [checked](../statements/checked-and-unchecked.md), [unchecked](../statements/checked-and-unchecked.md), [default](default.md), [nameof](nameof.md), [delegate](delegate-operator.md), [sizeof](sizeof.md), [stackalloc](stackalloc.md), [x->y](pointer-related-operators.md#pointer-member-access-operator--) | Primary | | [+x](arithmetic-operators.md#unary-plus-and-minus-operators), [-x](arithmetic-operators.md#unary-plus-and-minus-operators), [\!x](boolean-logical-operators.md#logical-negation-operator-), [~x](bitwise-and-shift-operators.md#bitwise-complement-operator-), [++x](arithmetic-operators.md#increment-operator-), [--x](arithmetic-operators.md#decrement-operator---), [^x](member-access-operators.md#index-from-end-operator-), [(T)x](type-testing-and-cast.md#cast-expression), [await](await.md), [&x](pointer-related-operators.md#address-of-operator-), [*x](pointer-related-operators.md#pointer-indirection-operator-), [true and false](true-false-operators.md) | Unary | | [x..y](member-access-operators.md#range-operator-) | Range | | [switch](switch-expression.md), [with](with-expression.md) | `switch` and `with` expressions | | [x * y](arithmetic-operators.md#multiplication-operator-), [x / y](arithmetic-operators.md#division-operator-), [x % y](arithmetic-operators.md#remainder-operator-) | Multiplicative| | [x + y](arithmetic-operators.md#addition-operator-), [x – y](arithmetic-operators.md#subtraction-operator--) | Additive | | [x \<\< y](bitwise-and-shift-operators.md#left-shift-operator-), [x >> y](bitwise-and-shift-operators.md#right-shift-operator-), [x >>> y](bitwise-and-shift-operators.md#unsigned-right-shift-operator-) | Shift | -| [x \< y](comparison-operators.md#less-than-operator-), [x > y](comparison-operators.md#greater-than-operator-), [x \<= y](comparison-operators.md#less-than-or-equal-operator-), [x >= y](comparison-operators.md#greater-than-or-equal-operator-), [is](type-testing-and-cast.md#is-operator), [as](type-testing-and-cast.md#as-operator) | Relational and type-testing | +| [x \< y](comparison-operators.md#less-than-operator-), [x > y](comparison-operators.md#greater-than-operator-), [x \<= y](comparison-operators.md#less-than-or-equal-operator-), [x >= y](comparison-operators.md#greater-than-or-equal-operator-), [is](type-testing-and-cast.md#the-is-operator), [as](type-testing-and-cast.md#the-as-operator) | Relational and type-testing | | [x == y](equality-operators.md#equality-operator-), [x != y](equality-operators.md#inequality-operator-) | Equality | | `x & y` | [Boolean logical AND](boolean-logical-operators.md#logical-and-operator-) or [bitwise logical AND](bitwise-and-shift-operators.md#logical-and-operator-) | | `x ^ y` | [Boolean logical XOR](boolean-logical-operators.md#logical-exclusive-or-operator-) or [bitwise logical XOR](bitwise-and-shift-operators.md#logical-exclusive-or-operator-) | diff --git a/docs/csharp/language-reference/operators/is.md b/docs/csharp/language-reference/operators/is.md index 95203660c6f3d..b3d9e710493c0 100644 --- a/docs/csharp/language-reference/operators/is.md +++ b/docs/csharp/language-reference/operators/is.md @@ -10,7 +10,7 @@ helpviewer_keywords: --- # is operator (C# reference) -The `is` operator checks if the result of an expression is compatible with a given type. For information about the type-testing `is` operator, see the [is operator](type-testing-and-cast.md#is-operator) section of the [Type-testing and cast operators](type-testing-and-cast.md) article. You can also use the `is` operator to match an expression against a pattern, as the following example shows: +The `is` operator checks if the result of an expression is compatible with a given type. For information about the type-testing `is` operator, see the [is operator](type-testing-and-cast.md#the-is-operator) section of the [Type-testing and cast operators](type-testing-and-cast.md) article. You can also use the `is` operator to match an expression against a pattern, as the following example shows: :::code language="csharp" source="snippets/shared/IsOperator.cs" id="IntroExample"::: diff --git a/docs/csharp/language-reference/operators/operator-overloading.md b/docs/csharp/language-reference/operators/operator-overloading.md index c61d47e5f4a02..98a9375f0cffa 100644 --- a/docs/csharp/language-reference/operators/operator-overloading.md +++ b/docs/csharp/language-reference/operators/operator-overloading.md @@ -46,7 +46,7 @@ The following table shows the operators that can't be overloaded: |[a[i]](member-access-operators.md#indexer-operator-), [`a?[i]`](member-access-operators.md#null-conditional-operators--and-)|Define an [indexer](../../programming-guide/indexers/index.md).| |[`(T)x`](type-testing-and-cast.md#cast-expression)|Define custom type conversions that can be performed by a cast expression. For more information, see [User-defined conversion operators](user-defined-conversion-operators.md).| |[`+=`](arithmetic-operators.md#compound-assignment), [`-=`](arithmetic-operators.md#compound-assignment), [`*=`](arithmetic-operators.md#compound-assignment), [`/=`](arithmetic-operators.md#compound-assignment), [`%=`](arithmetic-operators.md#compound-assignment), [`&=`](boolean-logical-operators.md#compound-assignment), [|=](boolean-logical-operators.md#compound-assignment), [`^=`](boolean-logical-operators.md#compound-assignment), [`<<=`](bitwise-and-shift-operators.md#compound-assignment), [`>>=`](bitwise-and-shift-operators.md#compound-assignment), [`>>>=`](bitwise-and-shift-operators.md#compound-assignment)|Overload the corresponding binary operator. For example, when you overload the binary `+` operator, `+=` is implicitly overloaded.| -|[`^x`](member-access-operators.md#index-from-end-operator-), [`x = y`](assignment-operator.md), [`x.y`](member-access-operators.md#member-access-expression-), [`x?.y`](member-access-operators.md#null-conditional-operators--and-), [`c ? t : f`](conditional-operator.md), [`x ?? y`](null-coalescing-operator.md), [`??= y`](null-coalescing-operator.md),
[`x..y`](member-access-operators.md#range-operator-), [`x->y`](pointer-related-operators.md#pointer-member-access-operator--), [`=>`](lambda-operator.md), [`f(x)`](member-access-operators.md#invocation-expression-), [`as`](type-testing-and-cast.md#as-operator), [`await`](await.md), [`checked`](../statements/checked-and-unchecked.md), [`unchecked`](../statements/checked-and-unchecked.md), [`default`](default.md), [`delegate`](delegate-operator.md), [`is`](type-testing-and-cast.md#is-operator), [`nameof`](nameof.md), [`new`](new-operator.md),
[`sizeof`](sizeof.md), [`stackalloc`](stackalloc.md), [`switch`](switch-expression.md), [`typeof`](type-testing-and-cast.md#typeof-operator), [`with`](with-expression.md)|None.| +|[`^x`](member-access-operators.md#index-from-end-operator-), [`x = y`](assignment-operator.md), [`x.y`](member-access-operators.md#member-access-expression-), [`x?.y`](member-access-operators.md#null-conditional-operators--and-), [`c ? t : f`](conditional-operator.md), [`x ?? y`](null-coalescing-operator.md), [`??= y`](null-coalescing-operator.md),
[`x..y`](member-access-operators.md#range-operator-), [`x->y`](pointer-related-operators.md#pointer-member-access-operator--), [`=>`](lambda-operator.md), [`f(x)`](member-access-operators.md#invocation-expression-), [`as`](type-testing-and-cast.md#the-as-operator), [`await`](await.md), [`checked`](../statements/checked-and-unchecked.md), [`unchecked`](../statements/checked-and-unchecked.md), [`default`](default.md), [`delegate`](delegate-operator.md), [`is`](type-testing-and-cast.md#the-is-operator), [`nameof`](nameof.md), [`new`](new-operator.md),
[`sizeof`](sizeof.md), [`stackalloc`](stackalloc.md), [`switch`](switch-expression.md), [`typeof`](type-testing-and-cast.md#the-typeof-operator), [`with`](with-expression.md)|None.| ## C# language specification diff --git a/docs/csharp/language-reference/operators/type-testing-and-cast.md b/docs/csharp/language-reference/operators/type-testing-and-cast.md index 73e67d3f4478a..65c7921bfed5a 100644 --- a/docs/csharp/language-reference/operators/type-testing-and-cast.md +++ b/docs/csharp/language-reference/operators/type-testing-and-cast.md @@ -23,7 +23,7 @@ helpviewer_keywords: --- # Type-testing operators and cast expressions - `is`, `as`, `typeof`, and casts -These operators and expressions perform type checking or type conversion. The `is` [operator](#is-operator) checks if the run-time type of an expression is compatible with a given type. The `as` [operator](#as-operator) explicitly converts an expression to a given type if its run-time type is compatible with that type. [Cast expressions](#cast-expression) perform an explicit conversion to a target type. The `typeof` [operator](#typeof-operator) obtains the instance for a type. +These operators and expressions perform type checking or type conversion. The `is` [operator](#the-is-operator) checks if the run-time type of an expression is compatible with a given type. The `as` [operator](#the-as-operator) explicitly converts an expression to a given type if its run-time type is compatible with that type. [Cast expressions](#cast-expression) perform an explicit conversion to a target type. The `typeof` [operator](#the-typeof-operator) obtains the instance for a type. ## The `is` operator @@ -131,7 +131,7 @@ An expression can't be an argument of the `typeof` operator. To get the type for best performance. In addition, the compiler issues a warning if a known `Lock` object is cast to another type and locked. If using an older version of .NET and C#, lock on a dedicated object instance that isn't used for another purpose. Avoid using the same lock object instance for different shared resources, as it might result in deadlock or lock contention. In particular, avoid using the following instances as lock objects: - `this`, as callers might also lock `this`. -- instances, as they might be obtained by the [typeof](../operators/type-testing-and-cast.md#typeof-operator) operator or reflection. +- instances, as they might be obtained by the [typeof](../operators/type-testing-and-cast.md#the-typeof-operator) operator or reflection. - string instances, including string literals, as they might be [interned](/dotnet/api/system.string.intern#remarks). Hold a lock for as short time as possible to reduce lock contention. diff --git a/docs/csharp/language-reference/toc.yml b/docs/csharp/language-reference/toc.yml index c83a835ca0297..fbbd94d62a0f1 100644 --- a/docs/csharp/language-reference/toc.yml +++ b/docs/csharp/language-reference/toc.yml @@ -74,8 +74,6 @@ items: href: ./builtin-types/unmanaged-types.md - name: Default values href: ./builtin-types/default-values.md - - name: Span types - href: ./builtin-types/span.md - name: Keywords items: - name: Overview diff --git a/docs/csharp/misc/cs0077.md b/docs/csharp/misc/cs0077.md index 750d8b295f7cc..48d6c38428f9f 100644 --- a/docs/csharp/misc/cs0077.md +++ b/docs/csharp/misc/cs0077.md @@ -12,7 +12,7 @@ ms.assetid: 55d3d290-d172-41a3-b326-ebf5a0a7e81f The as operator must be used with a reference type or nullable type ('int' is a non-nullable value type). - The [as](../language-reference/operators/type-testing-and-cast.md#as-operator) operator was passed a [value type](../language-reference/builtin-types/value-types.md). Because `as` can return [null](../language-reference/keywords/null.md), it can only be passed a [reference type](../language-reference/keywords/reference-types.md) or a [nullable value type](../language-reference/builtin-types/nullable-value-types.md). + The [as](../language-reference/operators/type-testing-and-cast.md#the-as-operator) operator was passed a [value type](../language-reference/builtin-types/value-types.md). Because `as` can return [null](../language-reference/keywords/null.md), it can only be passed a [reference type](../language-reference/keywords/reference-types.md) or a [nullable value type](../language-reference/builtin-types/nullable-value-types.md). However, using [pattern matching](../fundamentals/functional/pattern-matching.md) with the [is](../language-reference/operators/is.md) operator, we can directly perform type checking and assignments in one step. diff --git a/docs/csharp/misc/cs0244.md b/docs/csharp/misc/cs0244.md index 874d4c533e5e6..0f754637d1ee0 100644 --- a/docs/csharp/misc/cs0244.md +++ b/docs/csharp/misc/cs0244.md @@ -12,7 +12,7 @@ ms.assetid: f10e4479-ed6e-40dc-9fab-914e404d7f84 Neither 'is' nor 'as' is valid on pointer types - The [is](../language-reference/operators/type-testing-and-cast.md#is-operator) and [as](../language-reference/operators/type-testing-and-cast.md#as-operator) operators are not valid for use on pointer types. For more information, see [Unsafe Code and Pointers](../language-reference/unsafe-code.md). + The [is](../language-reference/operators/type-testing-and-cast.md#the-is-operator) and [as](../language-reference/operators/type-testing-and-cast.md#the-as-operator) operators are not valid for use on pointer types. For more information, see [Unsafe Code and Pointers](../language-reference/unsafe-code.md). The following sample generates CS0244: diff --git a/docs/csharp/misc/cs0837.md b/docs/csharp/misc/cs0837.md index 1bfd6ea5a421b..6c88f16d43435 100644 --- a/docs/csharp/misc/cs0837.md +++ b/docs/csharp/misc/cs0837.md @@ -14,7 +14,7 @@ ms.assetid: cbde45dc-222c-4bfe-8814-856476319d37 The first operand of an 'is' or 'as' operator may not be a lambda expression, anonymous method, or method group. - Lambda expressions, anonymous methods and method groups may not be used on the left side of [is](../language-reference/operators/type-testing-and-cast.md#is-operator) or [as](../language-reference/operators/type-testing-and-cast.md#as-operator). + Lambda expressions, anonymous methods and method groups may not be used on the left side of [is](../language-reference/operators/type-testing-and-cast.md#the-is-operator) or [as](../language-reference/operators/type-testing-and-cast.md#the-as-operator). ## To correct this error diff --git a/docs/csharp/programming-guide/types/casting-and-type-conversions.md b/docs/csharp/programming-guide/types/casting-and-type-conversions.md index 4611ba85a21ba..8b31036f299cd 100644 --- a/docs/csharp/programming-guide/types/casting-and-type-conversions.md +++ b/docs/csharp/programming-guide/types/casting-and-type-conversions.md @@ -66,7 +66,7 @@ In some reference type conversions, the compiler can't determine whether a cast :::code language="csharp" source="./snippets/CastingAndConversions/Program.cs" id="UnsafeCast"::: -Explicitly casting the argument `a` to a `Reptile` makes a dangerous assumption. It's safer to not make assumptions, but rather check the type. C# provides the [`is`](../../language-reference/operators/type-testing-and-cast.md#is-operator) operator to enable you to test for compatibility before actually performing a cast. For more information, see [How to safely cast using pattern matching and the as and is operators](../../fundamentals/tutorials/safely-cast-using-pattern-matching-is-and-as-operators.md). +Explicitly casting the argument `a` to a `Reptile` makes a dangerous assumption. It's safer to not make assumptions, but rather check the type. C# provides the [`is`](../../language-reference/operators/type-testing-and-cast.md#the-is-operator) operator to enable you to test for compatibility before actually performing a cast. For more information, see [How to safely cast using pattern matching and the as and is operators](../../fundamentals/tutorials/safely-cast-using-pattern-matching-is-and-as-operators.md). ## C# language specification diff --git a/docs/csharp/specification/toc.yml b/docs/csharp/specification/toc.yml index 2bed12107ef2a..aea248ca5cd93 100644 --- a/docs/csharp/specification/toc.yml +++ b/docs/csharp/specification/toc.yml @@ -170,7 +170,7 @@ items: - name: Extended nameof scope href: ../../../_csharplang/proposals/csharp-11.0/extended-nameof-scope.md - name: Unbound generic types in nameof - href: ../../../_csharp/proposals/unbound-generic-types-in-nameof.md + href: ../../../_csharplang/proposals/unbound-generic-types-in-nameof.md - name: Overload resolution priority href: ../../../_csharplang/proposals/csharp-13.0/overload-resolution-priority.md - name: Statements diff --git a/docs/csharp/whats-new/csharp-11.md b/docs/csharp/whats-new/csharp-11.md index 86dece0bec61c..7985746e2e287 100644 --- a/docs/csharp/whats-new/csharp-11.md +++ b/docs/csharp/whats-new/csharp-11.md @@ -45,7 +45,7 @@ public class TypeAttribute : Attribute } ``` -And to apply the attribute, you use the [`typeof`](../language-reference/operators/type-testing-and-cast.md#typeof-operator) operator: +And to apply the attribute, you use the [`typeof`](../language-reference/operators/type-testing-and-cast.md#the-typeof-operator) operator: ```csharp [TypeAttribute(typeof(string))] @@ -77,7 +77,7 @@ public class GenericType } ``` -The type arguments must satisfy the same restrictions as the [`typeof`](../language-reference/operators/type-testing-and-cast.md#typeof-operator) operator. Types that require metadata annotations aren't allowed. For example, the following types aren't allowed as the type parameter: +The type arguments must satisfy the same restrictions as the [`typeof`](../language-reference/operators/type-testing-and-cast.md#the-typeof-operator) operator. Types that require metadata annotations aren't allowed. For example, the following types aren't allowed as the type parameter: - `dynamic` - `string?` (or any nullable reference type) diff --git a/docs/csharp/whats-new/csharp-14.md b/docs/csharp/whats-new/csharp-14.md index 4520a815fd3c0..bd3bc960b9840 100644 --- a/docs/csharp/whats-new/csharp-14.md +++ b/docs/csharp/whats-new/csharp-14.md @@ -1,6 +1,6 @@ --- title: What's new in C# 14 -description: Get an overview of the new features in C# 13. +description: Get an overview of the new features in C# 14. C# 14 ships with .NET 10. ms.date: 02/04/2025 ms.topic: whats-new --- @@ -38,7 +38,7 @@ C# 14 introduces first-class support for ` and `ReadOnlySpan` are used in many key ways in C# and the runtime. Their introduction improves performance without risking safety. C# 14 recognizes the relationship between `ReadOnlySpan`, `Span`, and `T[]`. The span types can be extension method receivers, compose with other conversions, and help with generic type inference scenarios. -You can find the list of implicit span conversions in the article on [built-in types](../language-reference/builtin-types/built-in-types.md) in the language reference section. You can learn more details by reading the feature specification for [First class span types](~/_csharplang/proposals/first-class-span.md). +You can find the list of implicit span conversions in the article on [built-in types](../language-reference/builtin-types/built-in-types.md) in the language reference section. You can learn more details by reading the feature specification for [First class span types](~/_csharplang/proposals/first-class-span-types.md). ## Unbound generic types and nameof diff --git a/docs/framework/data/adonet/sql/linq/basic-data-types.md b/docs/framework/data/adonet/sql/linq/basic-data-types.md index f74488000f2a4..65a67339b9963 100644 --- a/docs/framework/data/adonet/sql/linq/basic-data-types.md +++ b/docs/framework/data/adonet/sql/linq/basic-data-types.md @@ -18,7 +18,7 @@ Because LINQ to SQL queries translate to Transact-SQL before they are executed o - Equal and Inequality Operator: Equality and inequality operators are supported for numeric, , , and types. For more about Visual Basic operators `=` and `<>`, see [Comparison Operators](../../../../../visual-basic/language-reference/operators/comparison-operators.md). For more information about C# comparison operators `==` and `!=`, see [Equality operators](../../../../../csharp/language-reference/operators/equality-operators.md). -- Is operator: The `IS` operator has a supported translation when inheritance mapping is being used. It can be used instead of directly testing the discriminator column to determine whether an object is of a specific entity type, and is translated to a check on the discriminator column. For more information about the Visual Basic and C# Is operators, see [Is Operator](../../../../../visual-basic/language-reference/operators/is-operator.md) and [is](../../../../../csharp/language-reference/operators/type-testing-and-cast.md#is-operator). +- Is operator: The `IS` operator has a supported translation when inheritance mapping is being used. It can be used instead of directly testing the discriminator column to determine whether an object is of a specific entity type, and is translated to a check on the discriminator column. For more information about the Visual Basic and C# Is operators, see [Is Operator](../../../../../visual-basic/language-reference/operators/is-operator.md) and [is](../../../../../csharp/language-reference/operators/type-testing-and-cast.md#the-is-operator). ## See also diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2263.md b/docs/fundamentals/code-analysis/quality-rules/ca2263.md index 572da2d56c8f1..26031debfd7e5 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2263.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2263.md @@ -30,7 +30,7 @@ A method overload that accepts a arg ## Rule description -Generic overloads are preferable to overloads that accept an argument of type when the type is known at compile time (using the [typeof operator](../../../csharp/language-reference/operators/type-testing-and-cast.md#typeof-operator) in C# or the [GetType operator](../../../visual-basic/language-reference/operators/gettype-operator.md) in Visual Basic). Generic overloads promote cleaner and more type-safe code with improved compile-time checks. +Generic overloads are preferable to overloads that accept an argument of type when the type is known at compile time (using the [typeof operator](../../../csharp/language-reference/operators/type-testing-and-cast.md#the-typeof-operator) in C# or the [GetType operator](../../../visual-basic/language-reference/operators/gettype-operator.md) in Visual Basic). Generic overloads promote cleaner and more type-safe code with improved compile-time checks. ## How to fix violations diff --git a/docs/fundamentals/code-analysis/style-rules/ide0082.md b/docs/fundamentals/code-analysis/style-rules/ide0082.md index e77a77b32d6eb..6f30073788f84 100644 --- a/docs/fundamentals/code-analysis/style-rules/ide0082.md +++ b/docs/fundamentals/code-analysis/style-rules/ide0082.md @@ -24,7 +24,7 @@ dev_langs: ## Overview -This style rule recommends use of the [nameof operator](../../../csharp/language-reference/operators/nameof.md) over the [typeof operator](../../../csharp/language-reference/operators/type-testing-and-cast.md#typeof-operator) followed by member access. It only fires when the name will be identical in both cases. +This style rule recommends use of the [nameof operator](../../../csharp/language-reference/operators/nameof.md) over the [typeof operator](../../../csharp/language-reference/operators/type-testing-and-cast.md#the-typeof-operator) followed by member access. It only fires when the name will be identical in both cases. ## Options @@ -81,6 +81,6 @@ For more information, see [How to suppress code analysis warnings](../suppress-w ## See also - [nameof operator](../../../csharp/language-reference/operators/nameof.md) -- [typeof operator](../../../csharp/language-reference/operators/type-testing-and-cast.md#typeof-operator) +- [typeof operator](../../../csharp/language-reference/operators/type-testing-and-cast.md#the-typeof-operator) - [Code style language rules](language-rules.md) - [Code style rules reference](index.md)