-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Corrected compiler error, inaccurate information in passing array topic #6336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| { | ||
| System.Console.Write(arr[i] + "{0}", i < arr.Length - 1 ? " " : ""); | ||
| Console.Write(arr[i] + "{0}", i < arr.Length - 1 ? " " : ""); | ||
| } |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
|
Closing and reopening to begin new build. |
|
Thank you so much for the thorough and careful review, @pkulikov! I've addressed all your comments. |
|
Closing and opening to restart build. |
|
|
||
| ### 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. |
There was a problem hiding this comment.
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
ChangeArraymethod reverses the array, and then theChangeArrayElementsmethod updates the first three elements of the array. After each method returns, theDisplayArraymethod shows that passing an array by value doesn't prevent changes to the array.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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 ![]()
|
|
||
| ### 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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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...
|
Thanks for taking a final look at the topic, @pkulikov. I've removed the unnecessary "to". |
Corrected compiler error, inaccurate information in passing array topic
Fixes #6325