You can do this using the overload of Array.Sort()
which takes two arrays and sorts the second one according to the order that it sorts the first one.
var array = new[] { 16, 5, 23, 1, 19 };
var indices = Enumerable.Range(0, array.Length).ToArray();
Array.Sort(array.ToArray(), indices);
var result = new int[array.Length];
for (int i = 0; i < result.Length; ++i)
result[indices[i]] = i;
// Now result[] contains the answer.
This uses a couple of O(n)
operations to make a copy of the array and to create the indices
array at the start, followed by an O(n log n)
sort, and finally finishes up with an O(n)
operation to rearrange result[]
.
(The algorithms presented in the other answers are likely a bit slower, but you probably really don't care unless you've already determined this functionality to require maxmimum speed - which seems unlikely.)