```csharp
//array
string[] colors = new string[4];
colors[0] = "Red";
colors[1] = "Blue";
colors[2] = "Green";
colors[3] = "Yellow";
Console.WriteLine(colors[3]);
//=====================================
//array initializer
//string[] colors = { "Red", "Blue", "Green", "Yellow" };
string[] colors;
colors = new string[] { "Red", "Blue", "Green", "Yellow" };
foreach (var item in colors)
{
Console.WriteLine(item);
}
//=====================================
string[] names = { "Janet", "Amy", "Peter", "Ben" };
//1.
string[] temp = new string[5];
//2.
Array.Copy(names, temp, names.Length);
//3.
names = temp;
foreach (var item in names)
{
Console.WriteLine(item);
}
//===========================
//resize
string[] names = { "Janet", "Amy", "Peter", "Ben" };
Array.Resize(ref names, 5);
foreach (var item in names)
{
Console.WriteLine(item ?? "xxxxx");
}
//===========================
//rank
string [] colors = new string [4];
Console.WriteLine( colors.Rank ); // 1
string [,] students = new string [4 , 5];
Console.WriteLine( students.Rank ); // 2
int [,,] points = new int [4 , 5 , 6];
Console.WriteLine( points.Rank ); // 3
//===========================
string[,] students = new string[4, 5];
int m = 0;
for (int i = 0; i < students.GetLength(0); i++)
{
for (int j = 0; j < students.GetLength(1); j++)
{
students[i, j] = $"student{++m:00}";
}
}
foreach (var item in students)
{
Console.WriteLine(item);
}
//==========================
//jagged array
string[][] seats = new string[3][];
seats[0] = new string[5];
seats[0][0] = "aaa";
seats[0][1] = "bbb";
seats[0][2] = "ccc";
seats[0][3] = "ddd";
seats[0][4] = "eee";
seats[1] = new string[] { "xxx", "yyy", "zzz" };
seats[2] = new string[6];
for (int i = 0; i < seats[2].Length; i++)
{
seats[2][i] = $"data {i+1}";
}
//Console.WriteLine(seats[0].ToString());
//Console.WriteLine(seats[0].GetType());
foreach (var item in seats)
{
foreach (var item1 in item)
{
Console.WriteLine(item1);
}
}
////======================
//arraylist
ArrayList list = new ArrayList();
list.Add(100);
list.Add(DateTime.Now);
Console.WriteLine((int)list[0] + 200);
Console.WriteLine(((DateTime)list[1]).ToShortDateString());
//======================
//list
List<int> list = new List<int>();
list.Add(100);
list.Add(200);
list.Add(300);
Console.WriteLine(list[0] + 200);
//======================
//dictionary<tkey, tvalue>
Dictionary<int, string> colors = new Dictionary<int, string>();
colors.Add(100, "red");
//colors.Add(200, "blue");
//colors.Add(200, "teal");
if(!colors.ContainsKey(200)) {
colors.Add(200, "teal");
}
colors.Add(300, "green");
// Console.WriteLine(colors[300]);
foreach (var item in colors)
{
Console.WriteLine($"{item.Key}, {item.Value}");
}
//======================
//collection initializer
List<int> list = new List<int> { 100, 200, 300 };
foreach (var item in list)
{
Console.WriteLine(item);
}
//Dictionary<int, string> colors = new Dictionary<int, string>
//{
// { 100, "red" },
// { 200, "blue" },
// { 300, "green" }
//};
Dictionary<int, string> colors = new Dictionary<int, string>
{
[100] = "red",
[200] = "blue",
[300] = "green"
};
foreach (var item in colors)
{
Console.WriteLine($"{item.Key}, {item.Value}");
}
//===========================
//tuple
var data=(100,"aaa",DateTime.Now);
Console.WriteLine(data.ToString());
Console.WriteLine(data);
Console.WriteLine((data.Item1+100, data.Item2.ToUpper(), data.Item3.ToShortTimeString()));
//============================
//deconstructing
//int id = 100;
//string name = "aaa";
//DateTime time = DateTime.Now;
(int id, string name, DateTime time) = (100, "aaa", DateTime.Now);
Console.WriteLine((id, name, time));
//============================
//item name
var data = (id:100, name:"aaa", time:DateTime.Now);
Console.WriteLine((data.Item1 + 100, data.Item2.ToUpper(), data.Item3.ToShortTimeString()));
Console.WriteLine((data.id + 100, data.name.ToUpper(), data.time.ToShortTimeString()));
(int id, string name, DateTime time) data = (id: 100, name: "aaa", time: DateTime.Now);
Console.WriteLine((data.Item1 + 100, data.Item2.ToUpper(), data.Item3.ToShortTimeString()));
Console.WriteLine((data.id + 100, data.name.ToUpper(), data.time.ToShortTimeString()));
//============================
//tuple
var (i, j) = (100, 200);
Console.WriteLine((i,j));
(i, j) = (j, i);
Console.WriteLine((i,j));