问题是我发现我的方法需要从多个 char 变量构建一个 char 数组 -> char[]。有人能指出我正确的方向吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
string[] wordList = {
"Baseball", "Tackle", "Dubstep", "Ignorance", "Limitation", "Sausage",
"Destruction", "Patriot", "Computing", "Assembly", "Coding", "Hackers",
"Football", "Downward"
};
static void Main(string[] args)
{
int guessRemain = 7;
int wordSel = GenerateRandom();
Program o = new Program();
char[] wordChar = o.wordList[wordSel].ToLower().ToCharArray();
int MAX_BUF = wordChar.Length;
Console.WriteLine("\nHANGMAN v 1.0\n\n\n\n");
char[] userInput = PromptUserEntry();
char[] solution = ScanForMatchingLetter(wordChar, MAX_BUF, userInput);
Console.Read();
}
private static char ScanForMatchingLetter(char[] wordChar, int MAX_BUF, char[] userInput)
{
char[] solution = new char[MAX_BUF];
for (int i = 0; i < MAX_BUF; ++i)
{
if (userInput[0] == wordChar[i])
{
solution[i] = userInput[0];
}
}
return solution;
}
private static char[] PromptUserEntry()
{
Console.WriteLine("Pick a letter:");
char[] userInput = Console.ReadLine().ToCharArray();
return userInput;
}
private static void DisplayGuessLetterLine(char[] solution)
{
Console.Write(solution);
}
private static int GenerateRandom()
{
Random randNum = new Random();
int wordSel = randNum.Next(0, 13);
return wordSel;
}
}
}
我这里有一个返回类型问题;返回类型指定为 char,但我返回的是 char[]。