0
我需要幫助獲取此代碼來顯示數組,但代碼結構必須保持不變。我已經創建了兩個數組,我需要從各個方法同時顯示,我也需要搜索和顯示學生的標記進入 這是我的第一個代碼,我所做的和真的需要幫助,感謝無法顯示
class Program
{
static void Main()
{
collectStudentDetails();
promptForStudentQuery();
printStudentsmarks();
Console.ReadLine();
}
public static void collectStudentDetails()
{
Console.WriteLine("Please Specifiy How Many Student Details You Wish To Enter");
Console.WriteLine("");
int n = SafeReadInteger(0);
int[] StudentMarks = new int[n];
string[] StudentNames = new string[n];
for (int i = 0; i < StudentNames.Length; i++)
{
Console.WriteLine("Enter Name for student {0}", i + 1);
StudentNames[i] = SafeReadString(null);
Console.WriteLine("Enter Mark for Student {0}: ", i + 1);
StudentMarks[i] = SafeReadInteger(0);
}
}
static void findStudentmark()
{
bool foundStudent = false;
Console.WriteLine("Please Enter The Students Name To Find Their Marks");
Console.WriteLine("Please Press Enter To Continue");
Console.ReadLine();
}
static void printStudentsmarks()
{
Console.WriteLine("\nStudent Mark List");
Console.WriteLine("Please Press Enter To Continue");
Console.ReadLine();
promptForStudentQuery();
}
static bool promptForStudentQuery()
{
bool promptAgain = true;
Console.WriteLine();
Console.WriteLine(" 1. find a student's mark ");
Console.WriteLine(" 2. print all student marks");
Console.WriteLine(" 3. exit ");
Console.WriteLine();
int choice = SafeReadInteger(0);
if (choice == 1)
{
findStudentmark();
}
else if (choice == 2)
{
printStudentsmarks();
}
else if (choice == 3)
{
Environment.Exit(0);
}
else if (choice == 0)
{
Console.WriteLine("you entered an invalid option try again");
}
return promptAgain;
}
public static int SafeReadInteger(int defaultVal)
{
try
{
return int.Parse(System.Console.ReadLine());
}
catch
{
return defaultVal;
}
}
public static string SafeReadString(string defaultVal)
{
string temp = "";
temp = Console.ReadLine();
while (temp == "")
{
Console.WriteLine("You have entered nothing. Please enter a correct value.");
temp = Console.ReadLine();
}
return temp;
}
static void DisplayArray(int[] inputarray)
{
foreach (int x in inputarray)
{
Console.Write(" {0} ", x);
}
Console.WriteLine("");
}
static void DisplayArray2(string[] inputarray)
{
foreach (string x in inputarray)
{
Console.Write(" {0} ", x);
}
Console.WriteLine("");
}
}
你真的認爲6頁的代碼是** **最少我們爲了幫助你看到了什麼? – Snowbear
抱歉這麼久,我無法使用它必須在該結構中的列表 – mitch
@ nadirs,那不是真的 – Habib