private int? ObjectIndex(object obj) { int idx; if (objects.TryGetValue(obj, out idx)) { return idx; } else { objects.Add(obj, objects.Count); return null; } }