Skip to content

Conversation

@rpetrusha
Copy link
Contributor

Corrected compiler error, inaccurate information in passing array topic

Fixes #6325

@rpetrusha rpetrusha self-assigned this Jul 5, 2018
@rpetrusha rpetrusha requested a review from BillWagner July 5, 2018 22:40
{
System.Console.Write(arr[i] + "{0}", i < arr.Length - 1 ? " " : "");
Console.Write(arr[i] + "{0}", i < arr.Length - 1 ? " " : "");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole for loop can be replaced with the call to string.Join. That makes the method one-liner:

static void PrintArray(string[] arr) => Console.WriteLine(string.Join(" ", arr));

arr = (arr.Reverse()).ToArray();
// The following statement displays Sat as the first element in the array.
System.Console.WriteLine("arr[0] is {0} in ChangeArray.", arr[0]);
// // Reversing the array persists when the method returns.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: too many //
Also consider rephrasing: Reversing the array persists... -> The array stays reversed...


// Pass the array as an argument to PrintArray.
// Display the array elements.
PrintArray(weekDays);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: PrintArray -> DisplayArray and the comment above the call can be removed.


### Description
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.
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, the `ChangeArray` method is called to reverse the array elements, and then the `ChangeArrayElement` method is called to modify the first three elements of the array. After each method returns, the `PrintArray` method is called to show that passing an array by value does not prevent changes to the array elements.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, if you rename PrintArray to DisplayArray, don't forget to make it here as well.
Second, there is no ChangeArrayElement method, plural is used in the code: ChangeArrayElements

@rpetrusha
Copy link
Contributor Author

Closing and reopening to begin new build.

@rpetrusha rpetrusha closed this Jul 6, 2018
@rpetrusha rpetrusha reopened this Jul 6, 2018
@rpetrusha
Copy link
Contributor Author

Thank you so much for the thorough and careful review, @pkulikov! I've addressed all your comments.

@rpetrusha
Copy link
Contributor Author

Closing and opening to restart build.

@rpetrusha rpetrusha closed this Jul 10, 2018
@rpetrusha rpetrusha reopened this Jul 10, 2018

### Description
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.
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 is called to reverse the array elements, and then the `ChangeArrayElements` method is called to modify the first three elements of the array. After each method returns, the `PrintArray` method is called to show that passing an array by value does not prevent changes to the array elements.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in the last sentence: PrintArray -> DisplayArray
nit: @rpetrusha how do you like converting the last two sentences into the active voice?

Next, the ChangeArray method reverses the array, and then the ChangeArrayElements method updates the first three elements of the array. After each method returns, the DisplayArray method shows that passing an array by value doesn't prevent changes to the array.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: in the last sentence, the method should be DisplayArray, not PrintArray.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it a great deal, @pkulikov. Thanks for the suggestion -- it really improves the readability of the paragraph.

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much more clear, @rpetrusha I approved this PR, but I did notice one location where you are still using the previous method name of PrintArray instead of DisplayArray. Once you make that change, you can :shipit:


### Description
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.
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 is called to reverse the array elements, and then the `ChangeArrayElements` method is called to modify the first three elements of the array. After each method returns, the `PrintArray` method is called to show that passing an array by value does not prevent changes to the array elements.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: in the last sentence, the method should be DisplayArray, not PrintArray.


### Description
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.
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 to 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpetrusha the last nit: please remove not necessary "to" in ...the ChangeArrayElements method to modifies the first three elements...

@rpetrusha
Copy link
Contributor Author

Thanks for taking a final look at the topic, @pkulikov. I've removed the unnecessary "to".

@rpetrusha rpetrusha merged commit 6f8d7ee into dotnet:master Jul 12, 2018
@rpetrusha rpetrusha deleted the cs-arrays branch July 12, 2018 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants