您的位置:首页 > 编程语言 > C#

C#基础编码---打印数组

2009-11-19 16:19 225 查看
/*
question :打印数组
*/
using System;
namespace ArrayTest
{
class Test
{
//静态方法, 是指类可以直接调用, 不用实例化.
/*static void PrintArray(int ArrayLength)
{
int[] array = new int[ArrayLength];
for(int i=0; i < array.Length; i++)
{
array[i]=i;
}
Console.WriteLine("Print Array's Value");
foreach(int i in array)
{
Console.WriteLine("array[{0}]={1}",i, array[i]);
}
}*/
//如果定义为非静态类, 在调用的时间需要实例化
public void PrintArray(int ArrayLength)
{
int[] array = new int[ArrayLength];
for(int i=0; i < array.Length; i++)
{
array[i]=i;
}
Console.WriteLine("Print Array's Value");
foreach(int i in array)
{
Console.WriteLine("array[{0}]={1}",i, array[i]);
}
}
static void Main()
{
int i=1;
Test test1 = new Test(); //如果是静态类, 这句话可以不用
while(i>0)//作用是可以多次输入
{
Console.Write("Input Array's Length: ");
i = Int32.Parse(Console.ReadLine());
test1.PrintArray(i);//如果是调用的是静态类,test1.可以不用
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: