实现Ilist接口的类
类:

 功能齐全的集合
功能齐全的集合
1 using System;
using System;
2 using System.Collections;
using System.Collections;
3
4 namespace Relaction.Collections
namespace Relaction.Collections
5

 {
{
6
 /**//// <summary>
    /**//// <summary>
7 /// MyList 的摘要说明。
    /// MyList 的摘要说明。
8 /// </summary>
    /// </summary>
9 public class MyList:IList
    public class MyList:IList
10
 
     {
{
11 private ArrayList _list;
        private ArrayList _list;
12 public MyList()
        public MyList()
13
 
         {
{
14 _list = new ArrayList();
            _list = new ArrayList();
15 }
        }
16
 IList 成员#region IList 成员
        IList 成员#region IList 成员
17
18 public bool IsReadOnly
        public bool IsReadOnly
19
 
         {
{
20 get
            get
21
 
             {
{
22 return _list.IsReadOnly;
                return _list.IsReadOnly;
23 }
            }
24 }
        }
25
26 public object this[int index]
        public object this[int index]
27
 
         {
{
28 get
            get
29
 
             {
{
30 return _list[index];
                return _list[index];
31 }
            }
32 set
            set
33
 
             {
{
34 _list[index] = value;
                _list[index] = value;
35 }
            }
36 }
        }
37
38 public void RemoveAt(int index)
        public void RemoveAt(int index)
39
 
         {
{
40 _list.RemoveAt(index);
            _list.RemoveAt(index);
41 }
        }
42
43 public void Insert(int index, object value)
        public void Insert(int index, object value)
44
 
         {
{
45 _list.Insert(index,value);
            _list.Insert(index,value);
46 }
        }
47
48 public void Remove(object value)
        public void Remove(object value)
49
 
         {
{
50 _list.Remove(value);
            _list.Remove(value);
51 }
        }
52
53 public bool Contains(object value)
        public bool Contains(object value)
54
 
         {
{
55 return _list.Contains(value);
            return _list.Contains(value);
56 }
        }
57
58 public void Clear()
        public void Clear()
59
 
         {
{
60 _list.Clear();
            _list.Clear();
61 }
        }
62
63 public int IndexOf(object value)
        public int IndexOf(object value)
64
 
         {
{
65 return _list.IndexOf(value);
            return _list.IndexOf(value);
66 }
        }
67
68 public int Add(object value)
        public int Add(object value)
69
 
         {
{
70 return _list.Add(value);
            return _list.Add(value);
71 }
        }
72
73 public bool IsFixedSize
        public bool IsFixedSize
74
 
         {
{
75 get
            get
76
 
             {
{
77 return _list.IsFixedSize;
                return _list.IsFixedSize;
78 }
            }
79 }
        }
80
81 #endregion
        #endregion
82
83
 ICollection 成员#region ICollection 成员
        ICollection 成员#region ICollection 成员
84
85 public bool IsSynchronized
        public bool IsSynchronized
86
 
         {
{
87 get
            get
88
 
             {
{
89 return _list.IsSynchronized;
                return _list.IsSynchronized;
90 }
            }
91 }
        }
92
93 public int Count
        public int Count
94
 
         {
{
95 get
            get
96
 
             {
{
97 return _list.Count;
                return _list.Count;
98 }
            }
99 }
        }
100
101 public void CopyTo(Array array, int index)
        public void CopyTo(Array array, int index)
102
 
         {
{
103 _list.CopyTo(array,index);
            _list.CopyTo(array,index);
104 }
        }
105
106 public object SyncRoot
        public object SyncRoot
107
 
         {
{
108 get
            get
109
 
             {
{
110 return _list.SyncRoot;
                return _list.SyncRoot;
111 }
            }
112 }
        }
113
114 #endregion
        #endregion
115
116
 IEnumerable 成员#region IEnumerable 成员
        IEnumerable 成员#region IEnumerable 成员
117
118 public IEnumerator GetEnumerator()
        public IEnumerator GetEnumerator()
119
 
         {
{
120 return _list.GetEnumerator();
            return _list.GetEnumerator();
121 }
        }
122
123 #endregion
        #endregion
124 }
    }
125 }
}
客户:

 客户
客户
1 private void button8_Click(object sender, System.EventArgs e)
    private void button8_Click(object sender, System.EventArgs e)
2
 
         {
{
3 Relaction.Collections.MyList list = new Relaction.Collections.MyList();
            Relaction.Collections.MyList list = new Relaction.Collections.MyList();
4 list.Add(1);
            list.Add(1);
5 list.Add(2);
            list.Add(2);
6 for(int i =0;i<list.Count;i++)
            for(int i =0;i<list.Count;i++)
7
 
             {
{
8 label1.Text += list[i].ToString();
                label1.Text += list[i].ToString();
9 }
            }
10 }
        }

 功能齐全的集合
功能齐全的集合1
 using System;
using System;2
 using System.Collections;
using System.Collections;3

4
 namespace Relaction.Collections
namespace Relaction.Collections5


 {
{6

 /**//// <summary>
    /**//// <summary>7
 /// MyList 的摘要说明。
    /// MyList 的摘要说明。8
 /// </summary>
    /// </summary>9
 public class MyList:IList
    public class MyList:IList10

 
     {
{11
 private ArrayList _list;
        private ArrayList _list;12
 public MyList()
        public MyList()13

 
         {
{14
 _list = new ArrayList();
            _list = new ArrayList();15
 }
        }16

 IList 成员#region IList 成员
        IList 成员#region IList 成员17

18
 public bool IsReadOnly
        public bool IsReadOnly19

 
         {
{20
 get
            get21

 
             {
{22
 return _list.IsReadOnly;
                return _list.IsReadOnly;23
 }
            }24
 }
        }25

26
 public object this[int index]
        public object this[int index]27

 
         {
{28
 get
            get29

 
             {
{30
 return _list[index];
                return _list[index];31
 }
            }32
 set
            set33

 
             {
{34
 _list[index] = value;
                _list[index] = value;35
 }
            }36
 }
        }37

38
 public void RemoveAt(int index)
        public void RemoveAt(int index)39

 
         {
{40
 _list.RemoveAt(index);
            _list.RemoveAt(index);41
 }
        }42

43
 public void Insert(int index, object value)
        public void Insert(int index, object value)44

 
         {
{45
 _list.Insert(index,value);
            _list.Insert(index,value);46
 }
        }47

48
 public void Remove(object value)
        public void Remove(object value)49

 
         {
{50
 _list.Remove(value);
            _list.Remove(value);51
 }
        }52

53
 public bool Contains(object value)
        public bool Contains(object value)54

 
         {
{55
 return _list.Contains(value);
            return _list.Contains(value);56
 }
        }57

58
 public void Clear()
        public void Clear()59

 
         {
{60
 _list.Clear();
            _list.Clear();61
 }
        }62

63
 public int IndexOf(object value)
        public int IndexOf(object value)64

 
         {
{65
 return _list.IndexOf(value);
            return _list.IndexOf(value);66
 }
        }67

68
 public int Add(object value)
        public int Add(object value)69

 
         {
{70
 return _list.Add(value);
            return _list.Add(value);71
 }
        }72

73
 public bool IsFixedSize
        public bool IsFixedSize74

 
         {
{75
 get
            get76

 
             {
{77
 return _list.IsFixedSize;
                return _list.IsFixedSize;78
 }
            }79
 }
        }80

81
 #endregion
        #endregion82

83

 ICollection 成员#region ICollection 成员
        ICollection 成员#region ICollection 成员84

85
 public bool IsSynchronized
        public bool IsSynchronized86

 
         {
{87
 get
            get88

 
             {
{89
 return _list.IsSynchronized;
                return _list.IsSynchronized;90
 }
            }91
 }
        }92

93
 public int Count
        public int Count94

 
         {
{95
 get
            get96

 
             {
{97
 return _list.Count;
                return _list.Count;98
 }
            }99
 }
        }100

101
 public void CopyTo(Array array, int index)
        public void CopyTo(Array array, int index)102

 
         {
{103
 _list.CopyTo(array,index);
            _list.CopyTo(array,index);104
 }
        }105

106
 public object SyncRoot
        public object SyncRoot107

 
         {
{108
 get
            get109

 
             {
{110
 return _list.SyncRoot;
                return _list.SyncRoot;111
 }
            }112
 }
        }113

114
 #endregion
        #endregion115

116

 IEnumerable 成员#region IEnumerable 成员
        IEnumerable 成员#region IEnumerable 成员117

118
 public IEnumerator GetEnumerator()
        public IEnumerator GetEnumerator()119

 
         {
{120
 return _list.GetEnumerator();
            return _list.GetEnumerator();121
 }
        }122

123
 #endregion
        #endregion124
 }
    }125
 }
}客户:

 客户
客户1
 private void button8_Click(object sender, System.EventArgs e)
    private void button8_Click(object sender, System.EventArgs e)2

 
         {
{3
 Relaction.Collections.MyList list = new Relaction.Collections.MyList();
            Relaction.Collections.MyList list = new Relaction.Collections.MyList();4
 list.Add(1);
            list.Add(1);5
 list.Add(2);
            list.Add(2);6
 for(int i =0;i<list.Count;i++)
            for(int i =0;i<list.Count;i++)7

 
             {
{8
 label1.Text += list[i].ToString();
                label1.Text += list[i].ToString();9
 }
            }10
 }
        }.jpg) 
  
 
                    
                
 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号