字符串數組:
using System;
class MyClass
{
static void Main()
{
string[] arr = new string[3] { "aa", "bb", "cc" };
foreach (string s in arr) Console.WriteLine(s); // aa/bb/cc
Console.ReadKey();
}
}
整數數組:
using System;
class MyClass
{
static void Main()
{
int[] arr = { 11, 22, 33 };
foreach (int i in arr) Console.WriteLine(i); // 11/22/33
Console.ReadKey();
}
}
初始化時維數可以省略; 若不省略, 得一致:
using System;
class MyClass
{
static void Main()
{
int[] arr = new int[3] { 11, 22, 33 };
foreach (int i in arr) Console.WriteLine(i); // 11/22/33
Console.ReadKey();
}
}