public static int NormalizeIndex(int len, int index) { return index < 0 ? Math.Max(0, index + len) : Math.Min(index, len); }