【发布时间】:2015-12-03 20:02:58
【问题描述】:
我是 C# 新手,我想使用随机方法从实际数组列表中给我的值。但我似乎无法对其进行转换或使用 console.readline() 。这是我的代码。
static void Main(string[] args)
{
string[] mots = new string[] { "pomme", "animal", "pont", "ensemble", "visuel", "acronyme", "cellule", "article", "syllable", "programme" };
Random mot = new Random(mot.GetHashCode());
mot = Console.ReadLine();
Console.WriteLine(mots[mot.Next(9)]);
string mot = "pomme";
char[] charArray = mot.ToCharArray();
Array.IndexOf(charArray);
}
如何将输出转换为字符串以便之后使用?谢谢。
【问题讨论】:
-
你为什么要给
mot分配一个字符串,它是Random类的对象?!?你到底想用那个ReadLine做什么? -
Random!=string。首先,你应该知道 -
您在很多地方都使用了
mot(english = word) 变量,除了不编译之外,这也是令人困惑的事情。你能列出你希望用户输入什么样的值(如果有的话)以及程序应该如何处理这些输入?如果您以这种方式处理它,您和我们就更容易发现哪里出了问题。 -
嗨!抱歉有这么多错误,我正在尝试做一个程序,它会从数组中随机选择一个单词(对我来说是字符串)。然后用户将不得不尝试通过输入一些字母来客串该词。这就是为什么我需要解决这个问题。