public class TestObjss { Dictionary<int, string> dic = new Dictionary<int, string>(); string this[int index] { get { if (dic.TryGetValue(index, out var value)) return value; return null; } set { if (index > 10) { throw new Exception("超出范围"); } dic[index] = value; } } }