You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/builtin-types/nullable-value-types.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ The default value of a nullable value type represents `null`, that is, it's an i
25
25
26
26
You can use the [`is` operator with a type pattern](../operators/type-testing-and-cast.md#type-testing-with-pattern-matching) to both examine an instance of a nullable value type for `null` and retrieve a value of an underlying type:
You can also compare a variable of a nullable value type with `null` instead of using the `HasValue` property, as the following example shows:
41
41
42
-
[!code-csharp-interactive[use comparison with null](snippets/shared/NullableValueTypes.cs#CompareWithNull)]
42
+
[!code-csharp[use comparison with null](snippets/shared/NullableValueTypes.cs#CompareWithNull)]
43
43
44
44
## Conversion from a nullable value type to an underlying type
45
45
46
46
If you want to assign a value of a nullable value type to a non-nullable value type variable, you might need to specify the value to be assigned in place of `null`. Use the [null-coalescing operator `??`](../operators/null-coalescing-operator.md) to do that (you can also use the <xref:System.Nullable%601.GetValueOrDefault(%600)?displayProperty=nameWithType> method for the same purpose):
If you want to use the [default](default-values.md) value of the underlying value type in place of `null`, use the <xref:System.Nullable%601.GetValueOrDefault?displayProperty=nameWithType> method.
51
51
@@ -71,7 +71,7 @@ For the [comparison operators](../operators/comparison-operators.md) `<`, `>`, `
71
71
- neither greater than or equal to `null`
72
72
- nor less than `null`
73
73
74
-
[!code-csharp-interactive[relational and equality operators](snippets/shared/NullableValueTypes.cs#ComparisonOperators)]
74
+
[!code-csharp[relational and equality operators](snippets/shared/NullableValueTypes.cs#ComparisonOperators)]
75
75
76
76
For the [equality operator](../operators/equality-operators.md#equality-operator-)`==`, if both operands are `null`, the result is `true`, if only one of the operands is `null`, the result is `false`; otherwise, the contained values of operands are compared.
77
77
@@ -88,23 +88,23 @@ An instance of a nullable value type `T?` is [boxed](../../programming-guide/typ
88
88
89
89
You can unbox a boxed value of a value type `T` to the corresponding nullable value type `T?`, as the following example shows:
90
90
91
-
[!code-csharp-interactive[boxing and unboxing](snippets/shared/NullableValueTypes.cs#Boxing)]
91
+
[!code-csharp[boxing and unboxing](snippets/shared/NullableValueTypes.cs#Boxing)]
92
92
93
93
## How to identify a nullable value type
94
94
95
95
The following example shows how to determine whether a <xref:System.Type?displayProperty=nameWithType> instance represents a constructed nullable value type, that is, the <xref:System.Nullable%601?displayProperty=nameWithType> type with a specified type parameter `T`:
96
96
97
-
[!code-csharp-interactive[whether Type is nullable](snippets/shared/NullableValueTypes.cs#IsTypeNullable)]
97
+
[!code-csharp[whether Type is nullable](snippets/shared/NullableValueTypes.cs#IsTypeNullable)]
98
98
99
99
As the example shows, you use the [typeof](../operators/type-testing-and-cast.md#the-typeof-operator) operator to create a <xref:System.Type?displayProperty=nameWithType> instance.
100
100
101
101
If you want to determine whether an instance is of a nullable value type, don't use the <xref:System.Object.GetType%2A?displayProperty=nameWithType> method to get a <xref:System.Type> instance to be tested with the preceding code. When you call the <xref:System.Object.GetType%2A?displayProperty=nameWithType> method on an instance of a nullable value type, the instance is [boxed](#boxing-and-unboxing) to <xref:System.Object>. As boxing of a non-null instance of a nullable value type is equivalent to boxing of a value of the underlying type, <xref:System.Object.GetType%2A> returns a <xref:System.Type> instance that represents the underlying type of a nullable value type:
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:
Instead use the <xref:System.Nullable.GetUnderlyingType%2A?displayProperty=nameWithType> 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.
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/builtin-types/value-tuples.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ Typically, you use tuples to group loosely related data elements. In public APIs
39
39
40
40
You explicitly specify tuple fields names in a tuple initialization expression or in the definition of a tuple type, as the following example shows:
41
41
42
-
[!code-csharp-interactive[explicit field names](snippets/shared/ValueTuples.cs#ExplicitFieldNames)]
42
+
[!code-csharp[explicit field names](snippets/shared/ValueTuples.cs#ExplicitFieldNames)]
43
43
44
44
If you don't specify a field name, it may be inferred from the name of the corresponding variable in a tuple initialization expression, as the following example shows:
> Use .NET style rule [IDE0034](../../../fundamentals/code-analysis/style-rules/ide0034.md) to specify a preference on the use of the `default` literal in your codebase.
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/operators/delegate-operator.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,18 +10,18 @@ helpviewer_keywords:
10
10
11
11
The `delegate` operator creates an anonymous method that can be converted to a delegate type. An anonymous method can be converted to types such as <xref:System.Action?displayProperty=nameWithType> and <xref:System.Func%601?displayProperty=nameWithType> types used as arguments to many methods.
> Lambda expressions provide a more concise and expressive way to create an anonymous function. Use the [=> operator](lambda-operator.md) to construct a lambda expression:
> For more information about features of lambda expressions, for example, capturing outer variables, see [Lambda expressions](lambda-expressions.md).
21
21
22
22
When you use the `delegate` operator, you might omit the parameter list. If you do that, the created anonymous method can be converted to a delegate type with any list of parameters, as the following example shows:
That's the only functionality of anonymous methods not supported by lambda expressions. In all other cases, a lambda expression is a preferred way to write inline code. You can use [discards](../../fundamentals/functional/discards.md) to specify two or more input parameters of an anonymous method that aren't used by the method:
You can use an [expression body definition](../../programming-guide/statements-expressions-operators/expression-bodied-members.md) to provide a concise definition for a method, constructor, property, indexer, or finalizer.
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/operators/new-operator.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,11 +16,11 @@ The `new` operator creates a new instance of a type. You can also use the `new`
16
16
17
17
To create a new instance of a type, you typically invoke one of the [constructors](../../programming-guide/classes-and-structs/constructors.md) of that type using the `new` operator:
You can use an [object or collection initializer](../../programming-guide/classes-and-structs/object-and-collection-initializers.md) with the `new` operator to instantiate and initialize an object in one statement, as the following example shows:
22
22
23
-
[!code-csharp-interactive[constructor with initializer](snippets/shared/NewOperator.cs#ConstructorWithInitializer)]
23
+
[!code-csharp[constructor with initializer](snippets/shared/NewOperator.cs#ConstructorWithInitializer)]
24
24
25
25
### Target-typed `new`
26
26
@@ -36,19 +36,19 @@ If a target type of a `new` expression is unknown (for example, when you use the
36
36
37
37
You also use the `new` operator to create an array instance, as the following example shows:
Use array initialization syntax to create an array instance and populate it with elements in one statement. The following example shows various ways how you can do that:
0 commit comments