分享继承自List的集合类
生活随笔
收集整理的這篇文章主要介紹了
分享继承自List的集合类
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
繼承自List<>,實現ICloneable、IList<>、IList接口
/**/ ///?<summary>????????///?用于裝載數據集合的泛型類
????????///?</summary>
????????///?<typeparam?name="數據類型">裝載數據的類型</typeparam>
????????[Serializable]
???????? public ? class ?數據列表 < 數據類型 > ?:?List < 數據類型 > ,?ICloneable,?IList < 數據類型 > ,IList
???????? ... {
????????????/**////?<summary>
????????????///?默認構造函數
????????????///?</summary>
????????????public?數據列表()
????????????????:?base()
????????????...{
????????????}
????????????/**////?<summary>
????????????///?構造時添加一個集合到列表中
????????????///?</summary>
????????????///?<param?name="collection">一個集合,其元素被復制到新列表中。</param>
????????????public?數據列表(IEnumerable<數據類型>?collection)
????????????????:?base(collection)
????????????...{
????????????}
????????????/**////?<summary>
????????????///?構造時設定列表數據在改變前的容納長度
????????????///?</summary>
????????????///?<param?name="capaciti">長度</param>
????????????public?數據列表(int?capaciti)
????????????????:?base(capaciti)
????????????...{
????????????
????????????}
????????????/**////?<summary>
????????????///?XML序列化此對象
????????????///?</summary>
????????????public?void?使用XML序列化對象(string?路徑)
????????????...{
????????????????CoreFunction.輸入輸出.XML序列化對象<數據列表<數據類型>>(this,?路徑);
????????????}
????????????/**////?<summary>
????????????///?XML反序列化指定對象
????????????///?</summary>
????????????public?static?數據列表<數據類型>?使用XML反序列化對象(string?路徑)
????????????...{
????????????????return?CoreFunction.輸入輸出.XML反序列化對象<數據列表<數據類型>>(路徑);
????????????}
????????????/**////?<summary>
????????????///?二進制序列化此對象
????????????///?</summary>
????????????public?void?使用二進制序列化對象(string?路徑)
????????????...{
????????????????CoreFunction.輸入輸出.序列化對象(this,?路徑);
????????????}
????????????/**////?<summary>
????????????///?二進制反序列化指定對象
????????????///?</summary>
????????????public?static?數據列表<數據類型>?使用二進制反序列化對象(string?路徑)
????????????...{
????????????????return?(數據列表<數據類型>)CoreFunction.輸入輸出.反序列化對象(路徑);
????????????}
????????????ICloneable?成員#region?ICloneable?成員
????????????/**////?<summary>
????????????///?創建作為當前實例副本的新對象
????????????///?</summary>
????????????///?<returns>作為此實例副本的新對象</returns>
????????????public?object?Clone()
????????????...{
????????????????string?FileName?=?CoreFunction.變量.程序所在目錄路徑?+?"/"?+?DateTime.Now.ToFileTime()?+?""?+?DateTime.Now.GetHashCode()?+?""?+?this.GetHashCode();
????????????????this.使用二進制序列化對象(FileName);
????????????????object?o?=?使用二進制反序列化對象(FileName);
????????????????File.Delete(FileName);
????????????????return?o;
????????????}
????????????#endregion
????????????/**////?<summary>
????????????///?重寫ToString方法
????????????///?</summary>????
????????????public?override?string?ToString()
????????????...{
????????????????StringBuilder?S?=?new?StringBuilder();
????????????????foreach?(數據類型?f?in?this)
????????????????...{
????????????????????S.AppendLine(f.ToString());
????????????????}
????????????????return?S.ToString();
????????????}
????????????IList<數據類型>?成員#region?IList<數據類型>?成員
????????????int?IList<數據類型>.IndexOf(數據類型?item)
????????????...{
????????????????return?IndexOf(item);
????????????}
????????????void?IList<數據類型>.Insert(int?index,?數據類型?item)
????????????...{
????????????????Insert(index,?item);
????????????}
????????????void?IList<數據類型>.RemoveAt(int?index)
????????????...{
????????????????RemoveAt(index);
????????????}
????????????數據類型?IList<數據類型>.this[int?index]
????????????...{
????????????????get
????????????????...{
????????????????????return?this[index];
????????????????}
????????????????set
????????????????...{
????????????????????this[index]?=?value;
????????????????}
????????????}
????????????#endregion
????????????ICollection<數據類型>?成員#region?ICollection<數據類型>?成員
????????????void?ICollection<數據類型>.Add(數據類型?item)
????????????...{
????????????????Add(item);
????????????}
????????????void?ICollection<數據類型>.Clear()
????????????...{
????????????????Clear();
????????????}
????????????bool?ICollection<數據類型>.Contains(數據類型?item)
????????????...{
????????????????return?Contains(item);
????????????}
????????????void?ICollection<數據類型>.CopyTo(數據類型[]?array,?int?arrayIndex)
????????????...{
????????????????CopyTo(array,?arrayIndex);
????????????}
????????????int?ICollection<數據類型>.Count
????????????...{
????????????????get?...{?return?Count;?}
????????????}
????????????bool?ICollection<數據類型>.IsReadOnly
????????????...{
????????????????get?...{?return?false;?}
????????????}
????????????bool?ICollection<數據類型>.Remove(數據類型?item)
????????????...{
????????????????return?Remove(item);
????????????}
????????????#endregion
????????????IEnumerable<數據類型>?成員#region?IEnumerable<數據類型>?成員
????????????IEnumerator<數據類型>?IEnumerable<數據類型>.GetEnumerator()
????????????...{
????????????????foreach(數據類型?f?in?this)
????????????????...{
????????????????????yield?return?f;
????????????????}
????????????}
????????????#endregion
????????????IEnumerable?成員#region?IEnumerable?成員
????????????IEnumerator?IEnumerable.GetEnumerator()
????????????...{
????????????????foreach?(數據類型?f?in?this)
????????????????...{
????????????????????yield?return?f;
????????????????}
????????????}
????????????#endregion
????????????IList?成員#region?IList?成員
????????????int?IList.Add(object?value)
????????????...{
????????????????return?((IList)this).Add((數據類型)value);
????????????}
????????????void?IList.Clear()
????????????...{
????????????????Clear();
????????????}
????????????bool?IList.Contains(object?value)
????????????...{
????????????????return?Contains((數據類型)value);
????????????}
????????????int?IList.IndexOf(object?value)
????????????...{
????????????????return?IndexOf((數據類型)value);
????????????}
????????????void?IList.Insert(int?index,?object?value)
????????????...{
????????????????Insert(index,?(數據類型)value);
????????????}
????????????bool?IList.IsFixedSize
????????????...{
????????????????get?...{?return?((IList)this).IsFixedSize;?}
????????????}
????????????bool?IList.IsReadOnly
????????????...{
????????????????get?...{?return?((IList)this).IsReadOnly;?}
????????????}
????????????void?IList.Remove(object?value)
????????????...{
????????????????Remove((數據類型)value);
????????????}
????????????void?IList.RemoveAt(int?index)
????????????...{
????????????????RemoveAt(index);
????????????}
????????????object?IList.this[int?index]
????????????...{
????????????????get
????????????????...{
????????????????????return?this[index];
????????????????}
????????????????set
????????????????...{
????????????????????this[index]?=?(數據類型)value;
????????????????}
????????????}
????????????#endregion
????????????ICollection?成員#region?ICollection?成員
????????????void?ICollection.CopyTo(Array?array,?int?index)
????????????...{
????????????????((IList)this).CopyTo(array,?index);
????????????}
????????????int?ICollection.Count
????????????...{
????????????????get?...{?return?Count;?}
????????????}
????????????bool?ICollection.IsSynchronized
????????????...{
????????????????get?...{?return?((IList)this).IsSynchronized;?}
????????????}
????????????object?ICollection.SyncRoot
????????????...{
????????????????get?...{?return?((IList)this).SyncRoot;?}
????????????}
????????????#endregion
????????}
總結
以上是生活随笔為你收集整理的分享继承自List的集合类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机考研400分以上,考研400分无缘
- 下一篇: 软件使用 | Pycharm使用技巧大全