using System;
namespace MultiCampus
{
class Program
{
class MyList<T>
{
private T[] array;
public MyList()
{
array = new T[4];
}
public T this[int idx]
{
get
{
return array[idx];
}
set
{
if(idx >= array.Length)
{
Array.Resize<T>(ref array, idx + 1);
Console.WriteLine($"배열 사이즈조정 : {array.Length}");
}
array[idx] = value;
}
}
public int Length
{
get { return array.Length; }
}
}
static void Main(string[] args)
{
MyList<string> myList1 = new MyList<string>();
myList1[0] = "A";
myList1[1] = "B";
myList1[2] = "C";
myList1[3] = "D";
myList1[4] = "E";
for( int i = 0; i< myList1.Length; i++)
{
Console.WriteLine(myList1[i]);
}
MyList<int> myList2 = new MyList<int>();
myList2[0] = 100;
myList2[1] = 200;
myList2[2] = 300;
myList2[3] = 400;
myList2[4] = 500;
for (int i = 0; i < myList2.Length; i++)
{
Console.WriteLine(myList2[i]);
}
}
}
}