网上数组定义很多讲解,感觉很零散,这里总结一下,备忘
class Program
{
static void Main(string[] args)
{
//1.声明并初始化数组大小
//string[] array = new string[3];
//for (int i = 0; i < 3; i++)
//{
// array[i] = "a"+i.ToString();
//}
//2.声明并初始化数组的值
//string[] array = { "a1", "a2", "a3" };
//3.声明一个string数组
//string[] array;//声明数组
//array=new string[] {"a1","a2","a3"};//给数组初始化值
//4.声明一个string数组
string[] array;//声明数组
array = new string[3];//初始化数组大小
for (int i = 0; i < 3; i++)//给数组逐个赋值
{
array[i] = "a" + i.ToString();
}
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine(array[i]);
}
Console.ReadLine();
}
}