Я довольно новичок в программировании, но я пытаюсь вернуть метод методу, который содержит местоположение файла, которое зависит от желаемого пользователя. Я занимаюсь этим уже более дня и зациклился на том, как правильно вернуть значение, я держу его в себе, говоря, что не все пути кода возвращают значение. Как исправить это и есть путь код возвращается к главномуВернуть местоположение файла из оператора switch
public static string fileLocation()
{
int fileRequest = 10;
bool errorCheck = true;
string filePath;
while (errorCheck == true)
{
Console.Write(">Enter '1' through '9' to choose a hand.");
Console.Write("Enter '0' for random.");
fileRequest = Convert.ToInt16(Console.ReadLine());
switch (fileRequest)
{
case 0:
Console.WriteLine(">Random selection loading.");
Random rnd = new Random();
fileRequest = rnd.Next(10);
errorCheck = true;
return (null);
case 1:
Console.WriteLine(">Loading file one.");
filePath = Path.GetFullPath("Flush.txt");
errorCheck = false;
return (Convert.ToString(filePath));
case 2:
Console.WriteLine(">Loading file two.");
filePath = Path.GetFullPath("FourKind.txt");
errorCheck = false;
return (Convert.ToString(filePath));
case 3:
Console.WriteLine(">Loading file three.");
filePath = Path.GetFullPath("FullHouse.txt");
errorCheck = false;
return (Convert.ToString(filePath));
case 4:
Console.WriteLine(">Loading file four.");
filePath = Path.GetFullPath("Pair.txt");
errorCheck = false;
return (Convert.ToString(filePath));
case 5:
Console.WriteLine(">Loading file five.");
filePath = Path.GetFullPath("RoyalFlush.txt");
errorCheck = false;
return (Convert.ToString(filePath));
case 6:
Console.WriteLine(">Loading file six.");
filePath = Path.GetFullPath("Straight.txt");
errorCheck = false;
return (Convert.ToString(filePath));
case 7:
Console.WriteLine(">Loading file seven.");
filePath = Path.GetFullPath("StraightFlush.txt");
errorCheck = false;
return (Convert.ToString(filePath));
case 8:
Console.WriteLine(">Loading file eight.");
filePath = Path.GetFullPath("ThreeKind.txt");
errorCheck = false;
return (Convert.ToString(filePath));
case 9:
Console.WriteLine(">Loading file nine.");
filePath = Path.GetFullPath("TwoPair.txt");
errorCheck = false;
return (Convert.ToString(filePath));
default:
Console.WriteLine(">Invalid request.");
filePath = "Invalid";
errorCheck = true;
return (null);
}
}
Каков ваш код, который вы ожидаете, что он будет вести себя по-другому? Вы научились использовать отладчик IDE и проделывать код по строкам во время его выполнения? – mason
какая у тебя проблема ??? вы ничего не спрашивали ... – Gusman
Вы устанавливаете проверку ошибок на true, а затем имеете цикл, который запускается только в том случае, если он является ложным. Поэтому ваш оператор цикла и переключателя никогда не выполняет – dman2306