Skip to content

Commit 86adcc0

Browse files
authored
Merge pull request #5035 from dotnet/master
Update Live with current Master
2 parents 8c996b9 + 6bf84cd commit 86adcc0

File tree

136 files changed

+558
-878
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+558
-878
lines changed

docs/csharp/language-reference/compiler-options/unsafe-compiler-option.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "-unsafe (C# Compiler Options)"
3-
ms.date: 07/20/2015
3+
ms.date: 04/25/2018
44
ms.prod: .net
55
ms.technology:
66
- "devlang-csharp"
@@ -11,8 +11,6 @@ helpviewer_keywords:
1111
- "-unsafe compiler option [C#]"
1212
- "unsafe compiler option [C#]"
1313
- "/unsafe compiler option [C#]"
14-
ms.assetid: fdb77ed9-da03-45bd-bb7f-250704da1bcc
15-
caps.latest.revision: 19
1614
author: "BillWagner"
1715
ms.author: "wiwagn"
1816
---
@@ -36,6 +34,16 @@ The **-unsafe** compiler option allows code that uses the [unsafe](../../../csha
3634

3735
3. Select the **Allow Unsafe Code** check box.
3836

37+
### To add this option in a csproj file
38+
39+
Open the .csproj file for a project, and add the following elements:
40+
41+
```xml
42+
<PropertyGroup>
43+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
44+
</PropertyGroup>
45+
```
46+
3947
For information about how to set this compiler option programmatically, see <xref:VSLangProj80.CSharpProjectConfigurationProperties3.AllowUnsafeBlocks%2A>.
4048

4149
## Example

docs/csharp/language-reference/keywords/codesnippet/CSharp/fixed-statement_1.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/csharp/language-reference/keywords/codesnippet/CSharp/fixed-statement_2.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

docs/csharp/language-reference/keywords/codesnippet/CSharp/fixed-statement_3.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/csharp/language-reference/keywords/codesnippet/CSharp/fixed-statement_4.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

docs/csharp/language-reference/keywords/default-values-table.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ helpviewer_keywords:
1515
- "variables [C#], value types"
1616
- "constructors [C#], default constructor"
1717
- "types [C#], default constructor return values"
18-
ms.assetid: 4af2c1df-9e3a-48c1-83ac-b192986fc5bc
19-
caps.latest.revision: 12
2018
author: "BillWagner"
2119
ms.author: "wiwagn"
2220
---
2321
# Default values table (C# Reference)
22+
2423
The following table shows the default values of value types returned by the default constructors. Default constructors are invoked by using the `new` operator, as follows:
2524

2625
```csharp
@@ -37,26 +36,26 @@ Remember that using uninitialized variables in C# is not allowed.
3736

3837
|Value type|Default value|
3938
|----------------|-------------------|
40-
|[bool](../../../csharp/language-reference/keywords/bool.md)|`false`|
41-
|[byte](../../../csharp/language-reference/keywords/byte.md)|0|
42-
|[char](../../../csharp/language-reference/keywords/char.md)|'\0'|
43-
|[decimal](../../../csharp/language-reference/keywords/decimal.md)|0M|
44-
|[double](../../../csharp/language-reference/keywords/double.md)|0.0D|
45-
|[enum](../../../csharp/language-reference/keywords/enum.md)|The value produced by the expression (E)0, where E is the enum identifier.|
46-
|[float](../../../csharp/language-reference/keywords/float.md)|0.0F|
47-
|[int](../../../csharp/language-reference/keywords/int.md)|0|
48-
|[long](../../../csharp/language-reference/keywords/long.md)|0L|
49-
|[sbyte](../../../csharp/language-reference/keywords/sbyte.md)|0|
50-
|[short](../../../csharp/language-reference/keywords/short.md)|0|
51-
|[struct](../../../csharp/language-reference/keywords/struct.md)|The value produced by setting all value-type fields to their default values and all reference-type fields to `null`.|
52-
|[uint](../../../csharp/language-reference/keywords/uint.md)|0|
53-
|[ulong](../../../csharp/language-reference/keywords/ulong.md)|0|
54-
|[ushort](../../../csharp/language-reference/keywords/ushort.md)|0|
39+
|[bool](bool.md)|`false`|
40+
|[byte](byte.md)|0|
41+
|[char](char.md)|'\0'|
42+
|[decimal](decimal.md)|0M|
43+
|[double](double.md)|0.0D|
44+
|[enum](enum.md)|The value produced by the expression (E)0, where E is the enum identifier.|
45+
|[float](float.md)|0.0F|
46+
|[int](int.md)|0|
47+
|[long](long.md)|0L|
48+
|[sbyte](sbyte.md)|0|
49+
|[short](short.md)|0|
50+
|[struct](struct.md)|The value produced by setting all value-type fields to their default values and all reference-type fields to `null`.|
51+
|[uint](uint.md)|0|
52+
|[ulong](ulong.md)|0|
53+
|[ushort](ushort.md)|0|
5554

5655
## See also
57-
[C# Reference](../../../csharp/language-reference/index.md)
58-
[C# Programming Guide](../../../csharp/programming-guide/index.md)
59-
[Value Types Table](../../../csharp/language-reference/keywords/value-types-table.md)
60-
[Value Types](../../../csharp/language-reference/keywords/value-types.md)
61-
[Built-In Types Table](../../../csharp/language-reference/keywords/built-in-types-table.md)
62-
[Reference Tables for Types](../../../csharp/language-reference/keywords/reference-tables-for-types.md)
56+
[C# Reference](../index.md)
57+
[C# Programming Guide](../../programming-guide/index.md)
58+
[Value Types Table](value-types-table.md)
59+
[Value Types](value-types.md)
60+
[Built-In Types Table](built-in-types-table.md)
61+
[Reference Tables for Types](reference-tables-for-types.md)
Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "fixed Statement (C# Reference)"
3-
ms.date: 07/20/2015
3+
ms.date: 04/20/2018
44
ms.prod: .net
55
ms.technology:
66
- "devlang-csharp"
@@ -10,48 +10,65 @@ f1_keywords:
1010
- "fixed"
1111
helpviewer_keywords:
1212
- "fixed keyword [C#]"
13-
ms.assetid: 7ea6db08-ad49-4a7a-b934-d8c4acad1c3a
14-
caps.latest.revision: 24
1513
author: "BillWagner"
1614
ms.author: "wiwagn"
1715
---
1816
# fixed Statement (C# Reference)
19-
The `fixed` statement prevents the garbage collector from relocating a movable variable. The `fixed` statement is only permitted in an [unsafe](../../../csharp/language-reference/keywords/unsafe.md) context. `Fixed` can also be used to create [fixed size buffers](../../../csharp/programming-guide/unsafe-code-pointers/fixed-size-buffers.md).
20-
21-
The `fixed` statement sets a pointer to a managed variable and "pins" that variable during the execution of the statement. Without `fixed`, pointers to movable managed variables would be of little use since garbage collection could relocate the variables unpredictably. The C# compiler only lets you assign a pointer to a managed variable in a `fixed` statement.
22-
23-
[!code-csharp[csrefKeywordsFixedLock#1](../../../csharp/language-reference/keywords/codesnippet/CSharp/fixed-statement_1.cs)]
24-
25-
You can initialize a pointer by using an array, a string, a fixed-size buffer, or the address of a variable. The following example illustrates the use of variable addresses, arrays, and strings. For more information about fixed-size buffers, see [Fixed Size Buffers](../../../csharp/programming-guide/unsafe-code-pointers/fixed-size-buffers.md).
26-
27-
[!code-csharp[csrefKeywordsFixedLock#2](../../../csharp/language-reference/keywords/codesnippet/CSharp/fixed-statement_2.cs)]
28-
29-
You can initialize multiple pointers, as long as they are all of the same type.
30-
17+
18+
The `fixed` statement prevents the garbage collector from relocating a movable variable. The `fixed` statement is only permitted in an [unsafe](unsafe.md) context. `Fixed` can also be used to create [fixed size buffers](../../programming-guide/unsafe-code-pointers/fixed-size-buffers.md).
19+
20+
The `fixed` statement sets a pointer to a managed variable and "pins" that variable during the execution of the statement. Pointers to movable managed variables are useful only in a `fixed` context. Without a `fixed` context, garbage collection could relocate the variables unpredictably. The C# compiler only lets you assign a pointer to a managed variable in a `fixed` statement.
21+
22+
[!code-csharp[Accessing fixed memory](../../../../samples/snippets/csharp/keywords/FixedKeywordExamples.cs#1)]
23+
24+
You can initialize a pointer by using an array, a string, a fixed-size buffer, or the address of a variable. The following example illustrates the use of variable addresses, arrays, and strings. For more information about fixed-size buffers, see [Fixed Size Buffers](../../programming-guide/unsafe-code-pointers/fixed-size-buffers.md).
25+
26+
[!code-csharp[Initializing fixed size buffers](../../../../samples/snippets/csharp/keywords/FixedKeywordExamples.cs#2)]
27+
28+
Multiple pointers can be initialized in one statement if they are all the same type:
29+
3130
```csharp
32-
fixed (byte* ps = srcarray, pd = dstarray) {...}
31+
fixed (byte* ps = srcarray, pd = dstarray) {...}
3332
```
34-
35-
To initialize pointers of different types, simply nest `fixed` statements, as shown in the following example.
36-
37-
[!code-csharp[csrefKeywordsFixedLock#3](../../../csharp/language-reference/keywords/codesnippet/CSharp/fixed-statement_3.cs)]
38-
39-
After the code in the statement is executed, any pinned variables are unpinned and subject to garbage collection. Therefore, do not point to those variables outside the `fixed` statement.
40-
41-
> [!NOTE]
42-
> Pointers initialized in fixed statements cannot be modified.
43-
44-
In unsafe mode, you can allocate memory on the stack, where it is not subject to garbage collection and therefore does not need to be pinned. For more information, see [stackalloc](../../../csharp/language-reference/keywords/stackalloc.md).
45-
46-
## Example
47-
[!code-csharp[csrefKeywordsFixedLock#4](../../../csharp/language-reference/keywords/codesnippet/CSharp/fixed-statement_4.cs)]
48-
49-
## C# Language Specification
50-
[!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)]
51-
52-
## See Also
53-
[C# Reference](../../../csharp/language-reference/index.md)
54-
[C# Programming Guide](../../../csharp/programming-guide/index.md)
55-
[C# Keywords](../../../csharp/language-reference/keywords/index.md)
56-
[unsafe](../../../csharp/language-reference/keywords/unsafe.md)
57-
[Fixed Size Buffers](../../../csharp/programming-guide/unsafe-code-pointers/fixed-size-buffers.md)
33+
34+
To initialize pointers of different types, simply nest `fixed` statements, as shown in the following example.
35+
36+
[!code-csharp[Initializing multiple pointers](../../../../samples/snippets/csharp/keywords/FixedKeywordExamples.cs#3)]
37+
38+
After the code in the statement is executed, any pinned variables are unpinned and subject to garbage collection. Therefore, do not point to those variables outside the `fixed` statement. The variables declared in the `fixed` statement are scoped to that statement, making this easier:
39+
40+
```csharp
41+
fixed (byte* ps = srcarray, pd = dstarray)
42+
{
43+
...
44+
}
45+
// ps and pd are no longer in scope here.
46+
```
47+
48+
Pointers initialized in `fixed` statements are readonly variables. If you want to modify the pointer value, you must declare a second pointer variable, and modify that. The variable declared in the `fixed` statement cannot be modified:
49+
50+
```csharp
51+
fixed (byte* ps = srcarray, pd = dstarray)
52+
{
53+
byte* pSourceCopy = ps;
54+
pSourceCopy++; // point to the next element.
55+
ps++; // invalid: cannot modify ps, as it is declared in the fixed statement.
56+
}
57+
```
58+
59+
60+
In unsafe mode, you can allocate memory on the stack, where it is not subject to garbage collection and therefore does not need to be pinned. For more information, see [stackalloc](stackalloc.md).
61+
62+
[!code-csharp[Initializing multiple pointers](../../../../samples/snippets/csharp/keywords/FixedKeywordExamples.cs#4)]
63+
64+
## C# Language Specification
65+
66+
[!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)]
67+
68+
## See Also
69+
70+
[C# Reference](../index.md)
71+
[C# Programming Guide](../../programming-guide/index.md)
72+
[C# Keywords](index.md)
73+
[unsafe](unsafe.md)
74+
[Fixed Size Buffers](../../programming-guide/unsafe-code-pointers/fixed-size-buffers.md)

docs/csharp/programming-guide/concepts/linq/linq-to-adonet-portal-page.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ms.author: "wiwagn"
1919
> [!NOTE]
2020
> The [!INCLUDE[linq_adonet](~/includes/linq-adonet-md.md)] documentation is located in the ADO.NET section of the .NET Framework SDK: [LINQ and ADO.NET](http://msdn.microsoft.com/library/bf0c8f93-3ff7-49f3-8aed-f2b7ac938dec).
2121
22-
There are three separate ADO.NET [!INCLUDE[vbteclinqext](~/includes/vbteclinqext-md.md)] technologies: [!INCLUDE[linq_dataset](~/includes/linq-dataset-md.md)], [!INCLUDE[vbtecdlinq](~/includes/vbtecdlinq-md.md)], and [!INCLUDE[linq_entities](~/includes/linq-entities-md.md)]. [!INCLUDE[linq_dataset](~/includes/linq-dataset-md.md)] provides richer, optimized querying over the <xref:System.Data.DataSet>, [!INCLUDE[vbtecdlinq](~/includes/vbtecdlinq-md.md)] enables you to directly query [!INCLUDE[ssNoVersion](~/includes/ssnoversion-md.md)] database schemas, and [!INCLUDE[linq_entities](~/includes/linq-entities-md.md)] allows you to query an [!INCLUDE[adonet_edm](~/includes/adonet-edm-md.md)].
22+
There are three separate ADO.NET [!INCLUDE[vbteclinqext](~/includes/vbteclinqext-md.md)] technologies: [!INCLUDE[linq_dataset](~/includes/linq-dataset-md.md)], [!INCLUDE[vbtecdlinq](~/includes/vbtecdlinq-md.md)], and [!INCLUDE[linq_entities](~/includes/linq-entities-md.md)]. [!INCLUDE[linq_dataset](~/includes/linq-dataset-md.md)] provides richer, optimized querying over the <xref:System.Data.DataSet>, [!INCLUDE[vbtecdlinq](~/includes/vbtecdlinq-md.md)] enables you to directly query SQL Server database schemas, and [!INCLUDE[linq_entities](~/includes/linq-entities-md.md)] allows you to query an [!INCLUDE[adonet_edm](~/includes/adonet-edm-md.md)].
2323

2424
## LINQ to DataSet
2525
The <xref:System.Data.DataSet> is one of the most widely used components in [!INCLUDE[vstecado](~/includes/vstecado-md.md)], and is a key element of the disconnected programming model that [!INCLUDE[vstecado](~/includes/vstecado-md.md)] is built on. Despite this prominence, however, the <xref:System.Data.DataSet> has limited query capabilities.

docs/csharp/programming-guide/statements-expressions-operators/default-value-expressions.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
11
---
22
title: "Default value expressions (C# Programming Guide)"
33
description: "Default value expressions produce the default value for any reference type or value type"
4-
ms.date: 08/23/2017
4+
ms.date: 04/25/2018
55
ms.prod: .net
66
ms.technology:
77
- "devlang-csharp"
88
ms.topic: "article"
99
helpviewer_keywords:
1010
- "generics [C#], default keyword"
1111
- "default keyword [C#], generic programming"
12-
ms.assetid: b9daf449-4e64-496e-8592-6ed2c8875a98
13-
caps.latest.revision: 22
1412
author: "BillWagner"
1513
ms.author: "wiwagn"
1614
---
1715
# default value expressions (C# programming guide)
1816

19-
A default value expression produces the default value for a type. Default value expressions are particularly useful in generic classes and methods. One issue that arises using generics is how to assign a default value to a parameterized type `T` when you do not know the following in advance:
17+
A default value expression `default(T)` produces the default value of a type `T`. The following table shows which values are produced for various types:
18+
19+
|Type|Default value|
20+
|---------|---------|
21+
|Any reference type|`null`|
22+
|Numeric value type|Zero|
23+
|[bool](../../language-reference/keywords/bool.md)|`false`|
24+
|[char](../../language-reference/keywords/char.md)|`'\0'`|
25+
|[enum](../../language-reference/keywords/enum.md)|The value produced by the expression `(E)0`, where `E` is the enum identifier.|
26+
|[struct](../../language-reference/keywords/struct.md)|The value produced by setting all value type fields to their default value and all reference type fields to `null`.|
27+
|Nullable type|An instance for which the <xref:System.Nullable%601.HasValue%2A> property is `false` and the <xref:System.Nullable%601.Value%2A> property is undefined.|
28+
29+
Default value expressions are particularly useful in generic classes and methods. One issue that arises using generics is how to assign a default value of a parameterized type `T` when you don't know the following in advance:
2030

2131
- Whether `T` is a reference type or a value type.
22-
- If `T` is a value type, whether is a numeric value or a user-defined struct.
32+
- If `T` is a value type, whether it's a numeric value or a struct.
33+
34+
Given a variable `t` of a parameterized type `T`, the statement `t = null` is only valid if `T` is a reference type. The assignment `t = 0` only works for numeric value types but not for structs. To solve that, use a default value expression:
2335

24-
Given a variable `t` of a parameterized type `T`, the statement `t = null` is only valid if `T` is a reference type. The assignment `t = 0` only works for numeric value types but not for structs. The solution is to use a default value expression, which returns `null` for reference types (class types and interface types) and zero for numeric value types. For user-defined structs, it returns the struct initialized to the zero bit pattern, which produces 0 or `null` for each member depending on whether that member is a value or reference type. For nullable value types, `default` returns a <xref:System.Nullable%601?displayProperty=nameWithType>, which is initialized like any struct.
36+
```csharp
37+
T t = default(T);
38+
```
2539

2640
The `default(T)` expression is not limited to generic classes and methods. Default value expressions can be used with any managed type. Any of these expressions are valid:
2741

2842
[!code-csharp[csProgGuideGenerics#1](../../../../samples/snippets/csharp/programming-guide/statements-expressions-operators/default-value-expressions.cs)]
2943

30-
The following example from the `GenericList<T>` class shows how to use the `default(T)` operator in a generic class. For more information, see [Generics Overview](../generics/introduction-to-generics.md).
44+
The following example from the `GenericList<T>` class shows how to use the `default(T)` operator in a generic class. For more information, see [Introduction to Generics](../generics/introduction-to-generics.md).
3145

3246
[!code-csharp[csProgGuideGenerics#2](../../../../samples/snippets/csharp/VS_Snippets_VBCSharp/csProgGuideGenerics/CS/Generics.cs#Snippet41)]
3347

@@ -47,8 +61,9 @@ The following example shows many usages of the `default` literal in a default va
4761

4862
## See also
4963

50-
<xref:System.Collections.Generic>
64+
<xref:System.Collections.Generic>
5165
[C# Programming Guide](../index.md)
52-
[Generics](../generics/index.md)
66+
[Generics (C# Programming Guide)](../generics/index.md)
5367
[Generic Methods](../generics/generic-methods.md)
54-
[Generics](~/docs/standard/generics/index.md)
68+
[Generics in .NET](~/docs/standard/generics/index.md)
69+
[Default values table](../../language-reference/keywords/default-values-table.md)

docs/csharp/programming-guide/unsafe-code-pointers/codesnippet/CSharp/fixed-size-buffers_1.cs

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)