```
public IList<int> GrayCode(int n) {
IList<int> result = new List<int>(new int[]{0});
for(int i = 1, pow = 1; i <= n; i++, pow <<= 1)
for(int j = result.Count - 1; j >= 0; j--)
result.Add(result[j] | pow);
return result;
}
```