Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从列表c中随机生成特定数量的字符串#_C#_String_List_Random_Count - Fatal编程技术网

C# 从列表c中随机生成特定数量的字符串#

C# 从列表c中随机生成特定数量的字符串#,c#,string,list,random,count,C#,String,List,Random,Count,我可能还不知道如何正确地搜索解决方案,但我找不到与我在下面遇到的问题相关的任何东西: 我有一个包含21个单词的字符串列表 public static List<string> LevelOneWords = new List<string> { "As", "If", "Go", "Do", "So", "No", "Up", &qu

我可能还不知道如何正确地搜索解决方案,但我找不到与我在下面遇到的问题相关的任何东西:

我有一个包含21个单词的字符串列表

public static List<string> LevelOneWords = new List<string> { "As", "If", "Go", "Do", "So", "No", "Up", "Hi", "Me", "Be", "Ah", "An", "Aw", "Is", "Ok", "At", "We", "Am", "Ab", "Ex", "It"};
publicstaticlist LevelOneWords=新列表{“As”、“If”、“Go”、“Do”、“So”、“No”、“Up”、“Hi”、“Me”、“Be”、“Ah”、“An”、“Aw”、“Is”、“Ok”、“At”、“We”、“Am”、“Ab”、“Ex”、“It”};
在用户做出决定后,我如何继续生成特定数量的这些

因为
rand.Next(LevelOneWords.Count)
只允许从列表中的可用数量生成随机单词

但假设我想生成50个实例

这是一款Typer Shark游戏,在培训课程中,我希望用户可以自由选择生成多少单词


由于我是编程新手,我觉得StackOverFlow的社区非常有帮助,所以提前感谢大家

您可以使用循环使用
rand.Next()
X次:

List<string> selectedWords = new List<string>();

for (int i = 0; i < 50; ++i)
{
    string randomWord = LevelOneWords[rand.Next(LevelOneWords.Count)];
    selectedWords.Add(randomWord);
}
List selectedWords=新列表();
对于(int i=0;i<50;++i)
{
string randomWord=LevelOneWords[rand.Next(LevelOneWords.Count)];
选择单词。添加(随机单词);
}