dotnet / dotnet/csharpstandard

23.7 Array fixed statement code style

Open
#138 4 comments 0 reactions 0 assignees View on GitHub
type: clarity
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

A couple of things jumped out looking at the examples of the fixed statement around arrays:

``` csharp
for (int i = 0; i < a.Length; ++i)
```

The use of `++i` is quite unusual in my experience (in C#); there are rather more examples of `i++` in the standard. (There are a few other `++i` examples which should potentially be normalized at the same time.)

``` csharp
unsafe static void Fill(int* p, int count, int value) {
for (; count != 0; count--) *p++ = value;
}
```

Again this feels more like code that a C programmer might write; I would generally leave the parameter alone, and write this as

``` csharp
unsafe static void Fill(int* p, int count, int value) {
for (int i = 0; i < count; i++) *p++ = value;
}
```

(I'd really use braces of course, but I understand why we don't want to here.)

Do we want to try to change this sort of thing, or is it below the line?

(Perhaps we should create a task early in the C# 6 standardization process of "make all code samples consistent" and do it in one thorough pass.)

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.