Read和ReadLine区别和联系
方法 | 用途 | 例子 |
Read | 读入单个字符 | int i = Console.Read(); |
ReadLine | 读入一行 | string str = Console.ReadLine(); |
Write | 写一行 | Console.Write("Write: 1"); |
WriteLine | 写一行,并带上行结束符 | Console.WriteLine("Test Output Data with Line"); |
数组输入元素示例:
using System;
namespace Arraytst
{
class reversal
{
public static void Main()
{
//int i;
int[] myArray=new int[5];
for(int i=0;i<myArray.Length;i++)
{
myArray[i]=int.Parse(Console.ReadLine());
}
for(int i=0;i<myArray.Length;i++)
{
Console.Write("{0,5}",myArray[i]);
}
Console.Read();
}
}
}