Advertisement
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 govno_sobach_e
- {
- class DateTimeList
- {
- DateTime[] M;
- int count = 0;
- public DateTimeList(int cap)
- {
- M = new DateTime[cap];
- }
- public DateTime this[int ind]
- {
- get { return M[ind]; }
- set { M[ind] = value; }
- }
- public int Count
- {
- get { return count; }
- set { count = value; }
- }
- public int Capacity
- {
- get { return M.Length; }
- set
- {
- if (value < count)
- value = count;
- if (value != M.Length)
- {
- DateTime[] nm = new DateTime[value];
- Array.Copy(M, nm, count);
- M = nm;
- }
- }
- }
- public void Add(System.DateTime item)
- {
- if (count == Capacity)
- Capacity = count * 2;
- M[count] = item;
- count++;
- }
- public void Insert(int ind, System.DateTime item)
- {
- this.Add(M[count - 1]);
- for (int i = count - 1; i > ind; i--)
- M[i] = M[i - 1];
- M[ind] = item;
- }
- public int IndexOf(System.DateTime value, int startIndex, int count)
- {
- int i = startIndex;
- while(i < startIndex + count)
- {
- if (M[i] == value)
- return i;
- }
- return -1;
- }
- public void CopyTo(System.DateTime[] myTargetArray)
- {
- for (int i = 0; i < myTargetArray.Length; i++)
- this.Add(myTargetArray[i]);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- DateTimeList myc = new DateTimeList(6);
- myc.Add(new DateTime(2015, 11, 04));
- myc.Add(new DateTime(2015, 11, 04));
- myc.Add(new DateTime(2015, 11, 04));
- DateTime Val1 = new DateTime(2014, 11, 23);
- DateTime Val2 = new DateTime(2015, 11, 04);
- myc.Insert(1, Val1);
- DateTime[] Dat = new DateTime[4] { new DateTime(2015, 12, 04), new DateTime(2011, 11, 04), new DateTime(2015, 08, 04), new DateTime(2012, 11, 04) };
- for (int i = 0; i < myc.Count; i++)
- Console.WriteLine(myc[i]);
- // foreach(DateTime x in myc)
- // Console.WriteLine(x);
- Console.WriteLine(myc.IndexOf(Val2, 2, 3));
- Console.WriteLine("count={0}", myc.Count);
- Console.WriteLine("Capacity={0}", myc.Capacity);
- myc.CopyTo(Dat);
- for (int i = 0; i < myc.Count; i++)
- Console.WriteLine(" {0}", myc[i]);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement