And I would argue that this is exactly why S109 exists.
For this example, I think it’s different.
byte[] bytes = new byte[10];
var time = DateTime.Now;
bytes[3] = (byte)time.Year;
bytes[2] = (byte)time.Month;
bytes[1] = (byte)time.Day;
bytes[0] = (byte)time.Hour;
bytes[5] = (byte)time.Minute;
bytes[4] = (byte)time.Second;
When I read this, my head is spinning: why is this bizarre ordering in place? By using constants for those indexes, I do not think the story of the code will become clearer.
var time = DateTime.Now;
var bytes = new byte[10]
{
(byte)time.Hour,
(byte)time.Day,
(byte)time.Month,
(byte)time.Year,
(byte)time.Second,
(byte)time.Minute,
// ...
}
This is also not clear and I already feel the urgency to start using block comments like /* 0 */ to make the index better understood. You could argue that this code is bad in so many ways that no rule could safe the day. But lets for now assume that the order of the bytes is not in control of the person who had to write and/or maintain the code, than maybe just suppressing the issue here is fine?!
I agree with Corniel’s view. The rule works as expected in these cases. Muting it would silence a lot of findings. If you have a specific need where there is no better way to access an array, it is usually easy to workaround the rule by doing it inside a variable assignment.