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.可以不用
}
}
}
}
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.可以不用
}
}
}
}
相关文章推荐
- C#基础之数组排序,对象大小比较
- C#编码中,打印预览DataGridView的一段代码,稍作了修改,可以实现。
- C#超基础:Array类数组的用法
- C#基础学习:CSS——数组(Aarry)
- C#中字符串与字节数组互换的几种编码问题
- C#基础第二天-作业答案-九九乘法表-打印星星
- C#基础-006(1)if练习题 判断一个数是不是偶数,如果是偶数那么就加1并打印
- 【C#基础】实现URL Unicode编码,编码、解码相关整理
- C#基础 字符串与数组
- C#基础:通过委托给任何对象数组进行排序
- 基础:理解 数组与集合(C#,泛型 )
- C#中的数组基础知识点总结
- 在C#中如何打印出一个数组,以字符串的方式
- C#基础解析之Ⅳ 【数组和排序】
- 基础_C# 数组
- c#数组赋值基础教程 Array
- 【C#基础知识】之结构、数组及常用的几种排序方法总结
- c#基础知识——函数参数数组
- C#基础总结之三循环控制-for-数组-乘法表-arraylist