dotnet / dotnet/dotnet-api-docs

Potential unwanted placement of method parameter.

Open
#9,877 2 comments 0 reactions 0 assignees View on GitHub
area-System.Collections Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

In the provided C# code snippet from the **IEnumerable\ 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)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.