Skip to content

Commit 5e1970e

Browse files
authored
Merge pull request #6435 from dotnet/master
Update live with current master
2 parents d038bac + e73d849 commit 5e1970e

File tree

92 files changed

+167
-172
lines changed

Some content is hidden

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

92 files changed

+167
-172
lines changed
Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,47 @@
1-
class ArrayClass
1+
using System;
2+
3+
class ArrayExample
24
{
3-
static void PrintArray(string[] arr)
4-
{
5-
for (int i = 0; i < arr.Length; i++)
6-
{
7-
System.Console.Write(arr[i] + "{0}", i < arr.Length - 1 ? " " : "");
8-
}
9-
System.Console.WriteLine();
10-
}
5+
static void DisplayArray(string[] arr) => Console.WriteLine(string.Join(" ", arr));
116

12-
static void ChangeArray(string[] arr)
13-
{
14-
// The following attempt to reverse the array does not persist when
15-
// the method returns, because arr is a value parameter.
16-
arr = (arr.Reverse()).ToArray();
17-
// The following statement displays Sat as the first element in the array.
18-
System.Console.WriteLine("arr[0] is {0} in ChangeArray.", arr[0]);
19-
}
7+
// Change the array by reversing its elements.
8+
static void ChangeArray(string[] arr) => Array.Reverse(arr);
209

2110
static void ChangeArrayElements(string[] arr)
2211
{
23-
// The following assignments change the value of individual array
24-
// elements.
25-
arr[0] = "Sat";
26-
arr[1] = "Fri";
27-
arr[2] = "Thu";
28-
// The following statement again displays Sat as the first element
29-
// in the array arr, inside the called method.
30-
System.Console.WriteLine("arr[0] is {0} in ChangeArrayElements.", arr[0]);
12+
// Change the value of the first three array elements.
13+
arr[0] = "Mon";
14+
arr[1] = "Wed";
15+
arr[2] = "Fri";
3116
}
3217

3318
static void Main()
3419
{
3520
// Declare and initialize an array.
3621
string[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
22+
// Display the array elements.
23+
DisplayArray(weekDays);
24+
Console.WriteLine();
3725

38-
// Pass the array as an argument to PrintArray.
39-
PrintArray(weekDays);
40-
41-
// ChangeArray tries to change the array by assigning something new
42-
// to the array in the method.
26+
// Reverse the array.
4327
ChangeArray(weekDays);
28+
// Display the array again to verify that it stays reversed.
29+
Console.WriteLine("Array weekDays after the call to ChangeArray:");
30+
DisplayArray(weekDays);
31+
Console.WriteLine();
4432

45-
// Print the array again, to verify that it has not been changed.
46-
System.Console.WriteLine("Array weekDays after the call to ChangeArray:");
47-
PrintArray(weekDays);
48-
System.Console.WriteLine();
49-
50-
// ChangeArrayElements assigns new values to individual array
51-
// elements.
33+
// Assign new values to individual array elements.
5234
ChangeArrayElements(weekDays);
53-
54-
// The changes to individual elements persist after the method returns.
55-
// Print the array, to verify that it has been changed.
56-
System.Console.WriteLine("Array weekDays after the call to ChangeArrayElements:");
57-
PrintArray(weekDays);
35+
// Display the array again to verify that it has changed.
36+
Console.WriteLine("Array weekDays after the call to ChangeArrayElements:");
37+
DisplayArray(weekDays);
5838
}
5939
}
60-
// Output:
61-
// Sun Mon Tue Wed Thu Fri Sat
62-
// arr[0] is Sat in ChangeArray.
63-
// Array weekDays after the call to ChangeArray:
64-
// Sun Mon Tue Wed Thu Fri Sat
65-
//
66-
// arr[0] is Sat in ChangeArrayElements.
67-
// Array weekDays after the call to ChangeArrayElements:
68-
// Sat Fri Thu Wed Thu Fri Sat
40+
// The example displays the following output:
41+
// Sun Mon Tue Wed Thu Fri Sat
42+
//
43+
// Array weekDays after the call to ChangeArray:
44+
// Sat Fri Thu Wed Tue Mon Sun
45+
//
46+
// Array weekDays after the call to ChangeArrayElements:
47+
// Mon Wed Fri Wed Tue Mon Sun
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Passing Arrays as Arguments (C# Programming Guide)"
3-
ms.date: 07/20/2015
3+
ms.date: 07/05/2018
44
helpviewer_keywords:
55
- "arrays [C#], passing as arguments"
66
ms.assetid: f3a0971e-c87c-4a1f-8262-bc0a3b712772
@@ -11,48 +11,48 @@ Arrays can be passed as arguments to method parameters. Because arrays are refer
1111
## Passing Single-Dimensional Arrays As Arguments
1212
You can pass an initialized single-dimensional array to a method. For example, the following statement sends an array to a print method.
1313

14-
[!code-csharp[csProgGuideArrays#34](../../../csharp/programming-guide/arrays/codesnippet/CSharp/passing-arrays-as-arguments_1.cs)]
14+
[!code-csharp[csProgGuideArrays#34](codesnippet/CSharp/passing-arrays-as-arguments_1.cs)]
1515

1616
The following code shows a partial implementation of the print method.
1717

18-
[!code-csharp[csProgGuideArrays#33](../../../csharp/programming-guide/arrays/codesnippet/CSharp/passing-arrays-as-arguments_2.cs)]
18+
[!code-csharp[csProgGuideArrays#33](codesnippet/CSharp/passing-arrays-as-arguments_2.cs)]
1919

2020
You can initialize and pass a new array in one step, as is shown in the following example.
2121

22-
[!code-csharp[CsProgGuideArrays#35](../../../csharp/programming-guide/arrays/codesnippet/CSharp/passing-arrays-as-arguments_3.cs)]
22+
[!code-csharp[CsProgGuideArrays#35](codesnippet/CSharp/passing-arrays-as-arguments_3.cs)]
2323

2424
## Example
2525

2626
### Description
27-
In the following example, an array of strings is initialized and passed as an argument to a `PrintArray` method for strings. The method displays the elements of the array. Next, methods `ChangeArray` and `ChangeArrayElement` are called to demonstrate that sending an array argument by value does not prevent changes to the array elements.
27+
In the following example, an array of strings is initialized and passed as an argument to a `DisplayArray` method for strings. The method displays the elements of the array. Next, the `ChangeArray` method reverses the array elements, and then the `ChangeArrayElements` method modifies the first three elements of the array. After each method returns, the `DisplayArray` method shows that passing an array by value does not prevent changes to the array elements.
2828

2929
### Code
30-
[!code-csharp[csProgGuideArrays#30](../../../csharp/programming-guide/arrays/codesnippet/CSharp/passing-arrays-as-arguments_4.cs)]
30+
[!code-csharp[csProgGuideArrays#30](codesnippet/CSharp/passing-arrays-as-arguments_4.cs)]
3131

3232
## Passing Multidimensional Arrays As Arguments
3333
You pass an initialized multidimensional array to a method in the same way that you pass a one-dimensional array.
3434

35-
[!code-csharp[csProgGuideArrays#41](../../../csharp/programming-guide/arrays/codesnippet/CSharp/passing-arrays-as-arguments_5.cs)]
35+
[!code-csharp[csProgGuideArrays#41](codesnippet/CSharp/passing-arrays-as-arguments_5.cs)]
3636

3737
The following code shows a partial declaration of a print method that accepts a two-dimensional array as its argument.
3838

39-
[!code-csharp[csProgGuideArrays#36](../../../csharp/programming-guide/arrays/codesnippet/CSharp/passing-arrays-as-arguments_6.cs)]
39+
[!code-csharp[csProgGuideArrays#36](codesnippet/CSharp/passing-arrays-as-arguments_6.cs)]
4040

4141
You can initialize and pass a new array in one step, as is shown in the following example.
4242

43-
[!code-csharp[csProgGuideArrays#32](../../../csharp/programming-guide/arrays/codesnippet/CSharp/passing-arrays-as-arguments_7.cs)]
43+
[!code-csharp[csProgGuideArrays#32](codesnippet/CSharp/passing-arrays-as-arguments_7.cs)]
4444

4545
## Example
4646

4747
### Description
4848
In the following example, a two-dimensional array of integers is initialized and passed to the `Print2DArray` method. The method displays the elements of the array.
4949

5050
### Code
51-
[!code-csharp[csProgGuideArrays#31](../../../csharp/programming-guide/arrays/codesnippet/CSharp/passing-arrays-as-arguments_8.cs)]
51+
[!code-csharp[csProgGuideArrays#31](codesnippet/CSharp/passing-arrays-as-arguments_8.cs)]
5252

5353
## See Also
5454
[C# Programming Guide](../../../csharp/programming-guide/index.md)
55-
[Arrays](../../../csharp/programming-guide/arrays/index.md)
56-
[Single-Dimensional Arrays](../../../csharp/programming-guide/arrays/single-dimensional-arrays.md)
57-
[Multidimensional Arrays](../../../csharp/programming-guide/arrays/multidimensional-arrays.md)
58-
[Jagged Arrays](../../../csharp/programming-guide/arrays/jagged-arrays.md)
55+
[Arrays](index.md)
56+
[Single-Dimensional Arrays](single-dimensional-arrays.md)
57+
[Multidimensional Arrays](multidimensional-arrays.md)
58+
[Jagged Arrays](jagged-arrays.md)

docs/csharp/programming-guide/classes-and-structs/ref-returns.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ In addition, reference return values are not allowed on async methods. An asynch
2929

3030
## Defining a ref return value
3131

32-
You define a ref return value by adding the [ref](../../language-reference/keywords/ref.md) keyword to the return type of the method signature. For example, the following signature indicates that the `GetContactInformation` property returns a reference to a `Person` object to the caller:
32+
A method that returns a *reference return value* must satisfy the following two conditions:
3333

34-
```csharp
35-
public ref Person GetContactInformation(string fname, string lname);
36-
```
34+
- The method signature includes the [ref](../../language-reference/keywords/ref.md) keyword in front of the return type.
35+
- Each [return](../../language-reference/keywords/return.md) statement in the method body includes the [ref](../../language-reference/keywords/ref.md) keyword in front of the name of the returned instance.
3736

38-
In addition, the name of the object returned by each [return](../../language-reference/keywords/return.md) statement in the method body must be preceded by the [ref](../../language-reference/keywords/ref.md) keyword. For example, the following `return` statement returns a reference to a `Person` object named `p`:
37+
The following example shows a method that satisfies those conditions and returns a reference to a `Person` object named `p`:
3938

4039
```csharp
41-
return ref p;
40+
public ref Person GetContactInformation(string fname, string lname)
41+
{
42+
// ...method implementation...
43+
return ref p;
44+
}
4245
```
4346

4447
## Consuming a ref return value

docs/csharp/programming-guide/concepts/async/async-return-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ In the following example, the `GetLeisureHours` async method contains a `return`
2727

2828
When `GetLeisureHours` is called from within an await expression in the `ShowTodaysInfo` method, the await expression retrieves the integer value (the value of `leisureHours`) that's stored in the task returned by the `GetLeisureHours` method. For more information about await expressions, see [await](../../../../csharp/language-reference/keywords/await.md).
2929

30-
You can better understand how this happens by separating the call to `GetLeisureHours` from the application of `await`, as the following code shows. A call to method `GetLeisureHours` that isn't immediately awaited returns a `Task<int>`, as you would expect from the declaration of the method. The task is assigned to the `integerTask` variable in the example. Because `integerTask` is a <xref:System.Threading.Tasks.Task%601>, it contains a <xref:System.Threading.Tasks.Task%601.Result> property of type `TResult`. In this case, TResult represents an integer type. When `await` is applied to `integerTask`, the await expression evaluates to the contents of the <xref:System.Threading.Tasks.Task%601.Result%2A> property of `integerTask`. The value is assigned to the `ret` variable.
30+
You can better understand how this happens by separating the call to `GetLeisureHours` from the application of `await`, as the following code shows. A call to method `GetLeisureHours` that isn't immediately awaited returns a `Task<int>`, as you would expect from the declaration of the method. The task is assigned to the `infoTask` variable in the example. Because `infoTask` is a <xref:System.Threading.Tasks.Task%601>, it contains a <xref:System.Threading.Tasks.Task%601.Result> property of type `TResult`. In this case, `TResult` represents an integer type. When `await` is applied to `infoTask`, the await expression evaluates to the contents of the <xref:System.Threading.Tasks.Task%601.Result%2A> property of `infoTask`. The value is assigned to the `ret` variable.
3131

3232
> [!IMPORTANT]
3333
> The <xref:System.Threading.Tasks.Task%601.Result%2A> property is a blocking property. If you try to access it before its task is finished, the thread that's currently active is blocked until the task completes and the value is available. In most cases, you should access the value by using `await` instead of accessing the property directly. <br/> The previous example retrieved the value of the <xref:System.Threading.Tasks.Task%601.Result%2A> property to block the main thread so that the `ShowTodaysInfo` method could finish execution before the application ended.

docs/framework/wcf/feature-details/how-to-use-a-custom-user-name-and-password-validator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ By default, when a user name and password is used for authentication, Windows Co
4747

4848
2. Add a [\<wsHttpBinding>](../../../../docs/framework/configure-apps/file-schema/wcf/wshttpbinding.md) or [\<basicHttpBinding>](../../../../docs/framework/configure-apps/file-schema/wcf/basichttpbinding.md) element to the bindings section. For more information about creating an WCF binding element, see [How to: Specify a Service Binding in Configuration](../../../../docs/framework/wcf/how-to-specify-a-service-binding-in-configuration.md).
4949

50-
3. Set the `mode` attribute of the [\<security>](../../../../docs/framework/configure-apps/file-schema/wcf/security-of-wshttpbinding.md) or [\<security>](../../../../docs/framework/configure-apps/file-schema/wcf/security-of-basichttpbinding.md) to `Message`, `Transport`, `or``TransportWithMessageCredential`.
50+
3. Set the `mode` attribute of the [\<security>](../../../../docs/framework/configure-apps/file-schema/wcf/security-of-wshttpbinding.md) or [\<security>](../../../../docs/framework/configure-apps/file-schema/wcf/security-of-basichttpbinding.md) to `Message`, `Transport`, or `TransportWithMessageCredential`.
5151

5252
4. Set the `clientCredentialType` attribute of the [\<message>](../../../../docs/framework/configure-apps/file-schema/wcf/message-of-wshttpbinding.md) or [\<transport>](../../../../docs/framework/configure-apps/file-schema/wcf/transport-of-wshttpbinding.md).
5353

docs/framework/winforms/controls/attributes-in-windows-forms-controls.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The .NET Framework provides a variety of attributes you can apply to the members
2121
|<xref:System.ComponentModel.CategoryAttribute>|Specifies the name of the category in which to group the property or event when displayed in a <xref:System.Windows.Forms.PropertyGrid> control set to <xref:System.Windows.Forms.PropertySort.Categorized> mode.|
2222
|<xref:System.ComponentModel.DefaultValueAttribute>|Specifies the default value for a property.|
2323
|<xref:System.ComponentModel.DescriptionAttribute>|Specifies a description for a property or event.|
24-
|<xref:System.ComponentModel.DisplayNameAttribute>|Specifies the display name for a property, event, or `public``void` method that takes no arguments.|
24+
|<xref:System.ComponentModel.DisplayNameAttribute>|Specifies the display name for a property, event, or `public void` method that takes no arguments.|
2525
|<xref:System.ComponentModel.EditorAttribute>|Specifies the editor to use to change a property.|
2626
|<xref:System.ComponentModel.EditorBrowsableAttribute>|Specifies that a property or method is viewable in an editor.|
2727
|<xref:System.ComponentModel.Design.HelpKeywordAttribute>|Specifies the context keyword for a class or member.|

docs/framework/winforms/controls/how-to-insert-a-menustrip-into-an-mdi-drop-down-menu-windows-forms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ In some applications, the kind of a multiple-document interface (MDI) child wind
3131

3232
7. Add a top-level menu item to the `Form2`<xref:System.Windows.Forms.MenuStrip> and set its <xref:System.Windows.Forms.ToolStripItem.Text%2A> property to `&File`.
3333

34-
8. Add submenu items to the `&File` menu of `Form2` in the following order: a <xref:System.Windows.Forms.ToolStripSeparator>, `&Save`, `&Close``and Save`, and another <xref:System.Windows.Forms.ToolStripSeparator>.
34+
8. Add submenu items to the `&File` menu of `Form2` in the following order: a <xref:System.Windows.Forms.ToolStripSeparator>, `&Save`, `Save and &Close`, and another <xref:System.Windows.Forms.ToolStripSeparator>.
3535

3636
9. Set the <xref:System.Windows.Forms.MergeAction> and <xref:System.Windows.Forms.ToolStripItem.MergeIndex%2A> properties of the `Form2` menu items as shown in the following table.
3737

docs/framework/wpf/advanced/dependency-property-value-precedence.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ ms.assetid: 1fbada8e-4867-4ed1-8d97-62c07dad7ebc
7878

7979
- **Default style**, also known as **theme style.** The <xref:System.Windows.FrameworkElement.Style%2A> property is not set directly, and in fact will read as `null` up until run time. In this case, the style comes from the run-time theme evaluation that is part of the [!INCLUDE[TLA2#tla_winclient](../../../../includes/tla2sharptla-winclient-md.md)] presentation engine.
8080

81-
For implicit styles not in themes, the type must match exactlya `MyButton``Button`-derived class will not implicitly use a style for `Button`.
81+
For implicit styles not in themes, the type must match exactly - a `MyButton` `Button`-derived class will not implicitly use a style for `Button`.
8282

8383
<a name="themestyles"></a>
8484
## Default (Theme) Styles

docs/framework/wpf/advanced/propertypath-xaml-syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The <xref:System.Windows.PropertyPath> object supports a complex inline [!INCLUD
4242
<Binding Path="[key]" .../>
4343
```
4444

45-
`key` must be either the typed index to a dictionary or hash table, or the integer index of an array. Also, the value of the key must be a type that is directly bindable to the property where it is applied. For instance, a hash table that contains string keys and string values can be used this way to bind to Text for a <xref:System.Windows.Controls.TextBox>. Or, if the key points to a collection or subindex, you could use this syntax to bind to a target collection property. Otherwise, you need to reference a specific property, through a syntax such as `<Binding Path="[``key``].``propertyName``" .../>`.
45+
`key` must be either the typed index to a dictionary or hash table, or the integer index of an array. Also, the value of the key must be a type that is directly bindable to the property where it is applied. For instance, a hash table that contains string keys and string values can be used this way to bind to Text for a <xref:System.Windows.Controls.TextBox>. Or, if the key points to a collection or subindex, you could use this syntax to bind to a target collection property. Otherwise, you need to reference a specific property, through a syntax such as `<Binding Path="[key].propertyName" .../>`.
4646

4747
You can specify the type of the index if necessary. For details on this aspect of an indexed property path, see <xref:System.Windows.Data.Binding.Path%2A?displayProperty=nameWithType>.
4848

0 commit comments

Comments
 (0)