using System using System Collections Generic using System Linq using

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
class Programm
{
public class DateTimeList
{
private List<DateTime> list = new List<DateTime>();
public DateTimeList(int capacity)
{
list = new List<DateTime>(capacity);
}
public void Add(DateTime item)
{
list.Add(item);
}
public void Reverse(int startIndex, int endIndex)
{
list.Reverse(startIndex, endIndex - startIndex + 1);
}
public void Clear()
{
list.Clear();
list.Capacity = 0;
}
public DateTime this[int index]
{
get { return list[index]; }
set { list[index] = value; }
}
public DateTimeList GetRangeIntList(int index, int count)
{
var new_list = new DateTimeList(count);
for (int i = index; i < index + count; i++)
{
new_list.Add(list[i]);
}
return new_list;
}
public int Capacity => list.Capacity;
public int Count => list.Count;
}
static void Main(string[] args)
{
var list = new DateTimeList(10);
list.Add(new DateTime(2015, 6, 1));
list.Add(new DateTime(2015, 6, 12));
list.Add(new DateTime(2015, 6, 3));
list.Add(new DateTime(2015, 6, 8));
list.Add(new DateTime(2015, 6, 5));
Console.WriteLine("Capacity : {0}", list.Capacity);
Console.WriteLine("Count : {0}", list.Count);
Console.WriteLine();
for (int i = 0; i < list.Count; i++)
{
Console.Write("{0} ", list[i].ToShortDateString());
}
Console.WriteLine();
list.Reverse(1, list.Count - 2);
for (int i = 0; i < list.Count; i++)
{
Console.Write("{0} ", list[i].ToShortDateString());
}
Console.WriteLine();
var sub_list = list.GetRangeIntList(1, 3);
for (int i = 0; i < sub_list.Count; i++)
{
Console.Write("{0} ", sub_list[i].ToShortDateString());
}
Console.WriteLine();
Console.WriteLine("Capacity : {0}", sub_list.Capacity);
Console.WriteLine("Count : {0}", sub_list.Count);
Console.WriteLine();
sub_list.Clear();
Console.WriteLine("Capacity : {0}", sub_list.Capacity);
Console.WriteLine("Count : {0}", sub_list.Count);
Console.WriteLine();
}
}
}