<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArrayOperation
{
class Program
{
static void Main(string[] args)
{
int[] a = { 123,12,245,1,2,45,67};//一维数组,类型为int
int[,] b = { {12,34,1,7},{23,345,12,45}};//二维数组,类型为int
string[] c = { "hello","World","你好"};//一维数组,类型为string
foreach (int i in a) {//输出a数组
System.Console.Write("{0} ",i);
}
System.Console.WriteLine();//换行
foreach (int j in b){//输出b数组
System.Console.Write("{0} ", j);
}
System.Console.WriteLine();//换行
foreach (string j in c){//输出c数组
System.Console.Write("{0} ", j);
}
System.Console.ReadLine();//方便看结果,免得结果一闪而过
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArrayOperation
{
class Program
{
static void Main(string[] args)
{
int[] a = { 123,12,245,1,2,45,67};//一维数组,类型为int
int[,] b = { {12,34,1,7},{23,345,12,45}};//二维数组,类型为int
string[] c = { "hello","World","你好"};//一维数组,类型为string
foreach (int i in a) {//输出a数组
System.Console.Write("{0} ",i);
}
System.Console.WriteLine();//换行
foreach (int j in b){//输出b数组
System.Console.Write("{0} ", j);
}
System.Console.WriteLine();//换行
foreach (string j in c){//输出c数组
System.Console.Write("{0} ", j);
}
System.Console.ReadLine();//方便看结果,免得结果一闪而过
}
}
}
本文通过C#代码示例展示了如何定义并遍历不同类型的数组,包括整型一维数组、二维数组及字符串数组,并提供了完整的输出结果展示。
726

被折叠的 条评论
为什么被折叠?



