dotnet/dotnet-api-docs

Potential unwanted placement of method parameter.

Opened this issue · 2 comments

In the provided C# code snippet from the IEnumerable<T> Interface documentation; https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1?view=net-8.0/#:~:text=1000%29.ToString%28%29%2C%20%22n%22%29

there appears to be a potential issue with the placement of a method parameter in the string.Format call within the example code. Specifically, the "n" parameter, which if understood correctly is intended to format the number with the thousand separators, is placed outside the format string, which may lead to improper functioning of the desired intent.

The problematic line in question is as follows:
string.Format(((memoryAfter - memoryBefore) / 1000).ToString(), "n") + "kb");

perhaps, to correctly produce the desired output, it should be:
string.Format("{0:n}kb", (memoryAfter - memoryBefore) / 1000));
(with an implicit casting of the expression's output into string due to the string.Format method, allowing to avoid the explicit conversion calling the method ToString)

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

Tagging subscribers to this area: @dotnet/area-system-collections