我希望以前没有人问过这个问题,有没有办法突出显示 return 语句应该在方法中使用的所有返回路径?因为我有一段相当长的代码块,其中包含可能的路径,但我仍然没有找到它上面的每条路径。(我认为这将是一个有用的工具)干杯。
static double findconversion(int menuOption, int submenuOption) {
if (menuOption == 1) {
if (submenuOption == 1) {
Console.Write("\nYou chose to convert Celcius to Fahrenheit" + "\nEnter the number that you want to convert, (between -500 and 500)"
+ "\nOr enter 0 to return to the previous menu: ");
double celnum = int.Parse(Console.ReadLine());
if (celnum == 0) {
Console.WriteLine("\nYou cancelled your selection"); return celnum;
} else if ((-500 > celnum) || (celnum > 500)) {
Console.WriteLine("\nchoose a number between -500 to 500 please");
findconversion(menuOption, submenuOption); return celnum;
} else if ((-500 <= celnum) && (celnum <= 500)) {
double result = Celsiusandfahrenheit(celnum, submenuOption);
if (submenuOption == 1) {
Console.WriteLine("\n " + celnum + (" degrees celcius converted to fahrenheit is: {0:0.00} degrees fahrenheit"), result);
return celnum;
} else if (submenuOption == 2) {
Console.WriteLine("\n " + celnum + (" degrees fahrenheit converted to celcius is: {0:0.00} degrees celcius"), result);
return celnum;
} return celnum;
}
} else if (submenuOption == 2) {
Console.Write("\nYou chose to convert Fahrenheit to Celsius" + "\nEnter the number that you want to convert, (between -500 and 500)"
+ "\nOr enter 0 to return to the previous menu: ");
double celnum = int.Parse(Console.ReadLine());
if (celnum == 0) {
Console.WriteLine("\nYou cancelled your selection"); return celnum;
} else if ((-500 > celnum) || (celnum > 500)) {
Console.WriteLine("\nchoose a number between -500 to 500 please");
findconversion(menuOption, submenuOption); return celnum;
} else if ((-500 <= celnum) && (celnum <= 500)) {
double result = Celsiusandfahrenheit(celnum, submenuOption);
if (submenuOption == 2) {
Console.WriteLine("\n " + celnum + (" degrees fahrenheit converted to celcius is: {0:0.00} degrees celcius"), result); return celnum;
}
} return celnum;
}
} else if (menuOption == 2) {
if (submenuOption == 1) {
Console.Write("\nYou chose to convert centimetres to feet and inches" + "\nEnter the number that you want to convert to feet and inches, (between -500 and 500)."
+ "\nOr enter 0 to return to the previous menu: ");
double celnum = int.Parse(Console.ReadLine());
if (celnum == 0) {
Console.WriteLine("\nYou cancelled your selection"); return celnum;
} else if ((-500 > celnum) || (celnum > 500)) {
Console.WriteLine("\nchoose a number between -500 to 500 please");
findconversion(menuOption, submenuOption); return celnum;
} else if ((-500 <= celnum) && (celnum <= 500)) {
double result = cmsandfeet(celnum, submenuOption);
// double result1 = cmsandinches(centnum, submenuOption, empty);
result = Math.Floor(result);
double result1 = ((celnum - (result * 30.48)) / 2.54);
if (submenuOption == 1) { Console.WriteLine("\n " + celnum + (" centimetres converted to feet and inches is: {0:0} feet and {1:0.00} inches"), result, result1); } return celnum;
}
return celnum;
}
}
}