字符串数组:
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();
}
}
时间: 2024-10-29 20:57:36