<p>I need to move backwards through an array, so I have code like this:</p>
<pre><code>for (int i = myArray.Length - 1; i &gt;= 0; i--)
{
    // Do something
    myArray[i] = 42;
}
</code></pre>
<p>Is there a better way of doing this?</p>
<p>Update: I was hoping that maybe C# had some built-in mechanism for this like:</p>
<pre><code>foreachbackwards (int i in myArray)
{
    // so easy
}
</code></pre>

That's definitely the best way for any array whose length is a signed integral type.  For arrays whose lengths are an unsigned integral type (e.g. an
```
std::vector
```
in C++), then you need to modify the end condition slightly:
```
```
for(size_t i = myArray.size() - 1; i != (size_t)-1; i--)
    // blah
```
```
If you just said
```
i >= 0
```
, this is always true for an unsigned integer, so the loop will be an infinite loop.