class StringBase : CollectionBase ...{ public string this[int index] ...{ get ...{ return ((string)List[index]); } set ...{ List[index] = value; } } public int Add(string value) ...{ return (List.Add(value)); } public int IndexOf(string value) ...{ return (List.IndexOf(value)); } public void Insert(int index, string value) ...{ List.Insert(index, value); } public void Remove(string value) ...{ List.Remove(value); } public bool Contains(string value) ...{ return (List.Contains(value)); } protected override void OnInsert(int index, object value) ...{ if (value.GetType() != Type.GetType("System.String")) throw new ArgumentException("value must be of type string.", "value"); base.OnInsert(index, value); } protected override void OnRemove(int index, object value) ...{ if (value.GetType() != Type.GetType("System.String")) throw new ArgumentException("value must be of type string.", "value"); base.OnRemove(index, value); } protected override void OnSet(int index, object oldValue, object newValue) ...{ if (newValue.GetType() != Type.GetType("System.String")) throw new ArgumentException("newValue must be of type string.", "newValue"); base.OnSet(index, oldValue, newValue); } protected override void OnValidate(object value) ...{ if (value.GetType() != Type.GetType("System.String")) throw new ArgumentException("value must be of type string."); base.OnValidate(value); } } 避免在增加不同类型数据时出错。