Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication14
- {
- class intList: System.Collections.ICollection
- {
- int count = 0;
- int[] M;
- const int defaultCapacity = 5;
- public intList(int capacity = defaultCapacity)
- {
- M = new int[capacity];
- }
- public int this[int i]
- {
- get { return M[i]; }
- set { M[i] = value; }
- }
- public int Capacity
- {
- get { return M.Length; }
- set
- {
- if (value < count) value = count;
- if (value != M.Length)
- {
- int[] a = new int[value];
- Array.Copy(M, 0, a, 0, count);
- M = a;
- }
- }
- }
- public int Count
- {
- get { return count; }
- }
- public void Add(int x)
- {
- if (count == Capacity) Capacity = count * 2;
- M[count] = x;
- count++;
- }
- public System.Collections.IEnumerator GetEnumerator()
- {
- for (int i = 0; i < this.Count; i++)
- {
- yield return M[i];
- }
- }
- public bool IsSynchronized
- {
- get;
- }
- public object SyncRoot
- {
- get;
- }
- public void addRange(System.Collections.ICollection a)
- {
- int[] b = new int[a.Count];
- a.CopyTo(b, 0);
- for (int j = 0; j < a.Count; j++)
- {
- this.Add(b[j]);
- }
- }
- void System.Collections.ICollection.CopyTo(System.Array a, int y)
- {
- for (int i = 0; i < this.Count - y; i++)
- {
- a.SetValue(this[i + y], i);
- }
- }
- public void SetRange(int n, System.Collections.ICollection a)
- {
- int i = 0;
- foreach (var obj in a)
- {
- this[i+n] = (int) obj;
- i++;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- intList IL = new intList(10);
- IL.Add(1);
- IL.Add(2);
- IL.Add(3);
- intList IL1 = new intList(10);
- IL1.Add(4);
- IL1.Add(5);
- IL.addRange(IL1);
- IL.SetRange(0, IL1);
- Console.WriteLine("count = {0}", IL.Count);
- Console.WriteLine("capacity = {0}", IL.Capacity);
- for (int i = 0; i < IL.Count;i++)
- {
- Console.Write("{0, 5}", IL[i]);
- }
- Console.WriteLine();
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment