【发布时间】:2017-10-22 18:31:03
【问题描述】:
这是我理解必须做的事情:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public const int N = 100;
static void Main(string[] args)
{
char[] phrase = new char[N];
int i=0;
Console.WriteLine("enter a phrase: ");
while ((i < N) && (phrase[i] != '.'))
{
phrase[i] = Convert.ToChar(Console.ReadLine());
i++;
}
while(i<N){
Console.WriteLine(+phrase[i]+" ");
i++;
}
Console.ReadLine();
}
}
}
我还想知道是否有一种方法可以输入短语,而无需为我介绍的每个字符按介绍
【问题讨论】:
-
...
Console.ReadLine给你一整行作为string,这就是你想要的。 -
那么如何使用 Console.ReadLine 来填充字符数组呢?
-
如果你真的需要一个字符数组,使用
ToCharArray方法。如果您只想表示一个有序的字符集合,请使用string- 这是它的设计目的。
标签: c# arrays string char phrase