Strong-Type Collection

自定义集合类:
ContractedBlock.gif ExpandedBlockStart.gif 自定义强类型集合类
  1None.gifusing System;
  2None.gifusing System.Collections;
  3None.gif
  4None.gifnamespace Relaction.Collections
  5ExpandedBlockStart.gifContractedBlock.gifdot.gif{
  6ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
  7InBlock.gif    /// 
  8ExpandedSubBlockEnd.gif    /// </summary>

  9InBlock.gif    public class MyStrongTypeList:IList
 10ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 11InBlock.gif        private ArrayList _list;
 12InBlock.gif        public MyStrongTypeList()
 13ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 14InBlock.gif            _list = new ArrayList();
 15ExpandedSubBlockEnd.gif        }

 16ContractedSubBlock.gifExpandedSubBlockStart.gif        IList 成员#region IList 成员
 17InBlock.gif
 18InBlock.gif        public bool IsReadOnly
 19ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 20InBlock.gif            get
 21ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 22InBlock.gif                return _list.IsReadOnly;
 23ExpandedSubBlockEnd.gif            }

 24ExpandedSubBlockEnd.gif        }

 25InBlock.gif
 26InBlock.gif        public object this[int index]
 27ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 28InBlock.gif            get
 29ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 30InBlock.gif                return _list[index];
 31ExpandedSubBlockEnd.gif            }

 32InBlock.gif            set
 33ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 34InBlock.gif                _list[index] = value;
 35ExpandedSubBlockEnd.gif            }

 36ExpandedSubBlockEnd.gif        }

 37InBlock.gif
 38InBlock.gif        public void RemoveAt(int index)
 39ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 40InBlock.gif            _list.RemoveAt(index);
 41ExpandedSubBlockEnd.gif        }

 42InBlock.gif
 43InBlock.gif        void IList.Insert(int index, object value)
 44ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 45InBlock.gif            _list.Insert(index,value);
 46ExpandedSubBlockEnd.gif        }

 47InBlock.gif
 48InBlock.gif        public void Insert(int index,string value)
 49ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 50InBlock.gif            ((IList)this).Insert(index,value);
 51ExpandedSubBlockEnd.gif        }

 52InBlock.gif
 53InBlock.gif        void IList.Remove(object value)
 54ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 55InBlock.gif            _list.Remove(value);
 56ExpandedSubBlockEnd.gif        }

 57InBlock.gif        public void Remove(string value)
 58ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 59InBlock.gif            ((IList)this).Remove(value);
 60ExpandedSubBlockEnd.gif        }

 61InBlock.gif
 62InBlock.gif        bool IList.Contains(object value)
 63ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 64InBlock.gif            return _list.Contains(value);
 65ExpandedSubBlockEnd.gif        }

 66InBlock.gif
 67InBlock.gif        public bool Contains(string value)
 68ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 69InBlock.gif            return ((IList)this).Contains(value);
 70ExpandedSubBlockEnd.gif        }

 71InBlock.gif
 72InBlock.gif        public void Clear()
 73ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 74InBlock.gif            _list.Clear();
 75ExpandedSubBlockEnd.gif        }

 76InBlock.gif
 77InBlock.gif        int IList.IndexOf(object value)
 78ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 79InBlock.gif            return _list.IndexOf(value);
 80ExpandedSubBlockEnd.gif        }

 81InBlock.gif
 82InBlock.gif        public int IndexOf(string value)
 83ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 84InBlock.gif            return ((IList)this).IndexOf(value);
 85ExpandedSubBlockEnd.gif        }

 86InBlock.gif
 87InBlock.gif        int IList.Add(object value)
 88ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 89InBlock.gif            return _list.Add(value);
 90ExpandedSubBlockEnd.gif        }

 91InBlock.gif
 92InBlock.gif        public int Add(string value)
 93ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 94InBlock.gif            return ((IList)this).Add(value);
 95ExpandedSubBlockEnd.gif        }

 96InBlock.gif
 97InBlock.gif        public bool IsFixedSize
 98ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 99InBlock.gif            get
100ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
101InBlock.gif                return _list.IsFixedSize;
102ExpandedSubBlockEnd.gif            }

103ExpandedSubBlockEnd.gif        }

104InBlock.gif
105ExpandedSubBlockEnd.gif        #endregion

106InBlock.gif
107ContractedSubBlock.gifExpandedSubBlockStart.gif        ICollection 成员#region ICollection 成员
108InBlock.gif
109InBlock.gif        public bool IsSynchronized
110ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
111InBlock.gif            get
112ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
113InBlock.gif                return _list.IsSynchronized;
114ExpandedSubBlockEnd.gif            }

115ExpandedSubBlockEnd.gif        }

116InBlock.gif
117InBlock.gif        public int Count
118ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
119InBlock.gif            get
120ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
121InBlock.gif                return _list.Count;
122ExpandedSubBlockEnd.gif            }

123ExpandedSubBlockEnd.gif        }

124InBlock.gif
125InBlock.gif        public void CopyTo(Array array, int index)
126ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
127InBlock.gif            _list.CopyTo(array,index);
128ExpandedSubBlockEnd.gif        }

129InBlock.gif
130InBlock.gif        public object SyncRoot
131ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
132InBlock.gif            get
133ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
134InBlock.gif                return _list.SyncRoot;
135ExpandedSubBlockEnd.gif            }

136ExpandedSubBlockEnd.gif        }

137InBlock.gif
138ExpandedSubBlockEnd.gif        #endregion

139InBlock.gif
140ContractedSubBlock.gifExpandedSubBlockStart.gif        IEnumerable 成员#region IEnumerable 成员
141InBlock.gif
142InBlock.gif        public IEnumerator GetEnumerator()
143ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
144InBlock.gif            return _list.GetEnumerator();
145ExpandedSubBlockEnd.gif        }

146InBlock.gif
147ExpandedSubBlockEnd.gif        #endregion

148ExpandedSubBlockEnd.gif    }

149ExpandedBlockEnd.gif}

150None.gif
客户代码:
ContractedBlock.gif ExpandedBlockStart.gif 客户代码
 1None.gif    private void button9_Click(object sender, System.EventArgs e)
 2ExpandedBlockStart.gifContractedBlock.gif        dot.gif{
 3InBlock.gif            Relaction.Collections.MyStrongTypeList list = new Relaction.Collections.MyStrongTypeList();
 4InBlock.gif            list.Add("1");
 5InBlock.gif            list.Add("2");
 6InBlock.gif            list.Add("nantest");
 7InBlock.gif            for(int i =0;i<list.Count;i++)
 8ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 9InBlock.gif                label1.Text += list[i].ToString();
10ExpandedSubBlockEnd.gif            }

11ExpandedBlockEnd.gif        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值