本文整理汇总了C#中Student.getCityOfReference方法的典型用法代码示例。如果您正苦于以下问题:C# Student.getCityOfReference方法的具体用法?C# Student.getCityOfReference怎么用?C# Student.getCityOfReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Student
的用法示例。
在下文中一共展示了Student.getCityOfReference方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//.........这里部分代码省略.........
} while (true);
Student st = new Student(lastName, firstName, course, studentId, sex, cityOfResidence, studentRecordbookId);
fileToWrite.WriteLine(st.stringify());
Console.Write("Do you want to add another student to list? [y/n] >>> ");
choice1 = Console.ReadLine();
while (!choice1.Equals("y") && !choice1.Equals("n"))
{
Console.WriteLine("Enter \"y\" for Yes or \"n\" for No >>> ");
choice1 = Console.ReadLine();
}
Console.WriteLine();
}
catch (IOException ioEx)
{
Console.WriteLine("[ERROR] I/O Exception: {0}", ioEx.Message);
return;
}
} while (choice1.Equals("y"));
fileToWrite.Close();
Console.WriteLine("Student's data was successfully written to file {0}\n", filePath);
}
catch (DirectoryNotFoundException dnfEx)
{
Console.WriteLine("[ERROR] Wrong file path: {0}", dnfEx.Message);
return;
}
catch (IOException ioEx)
{
Console.WriteLine("[ERROR] I/O Exception: {0}", ioEx.Message);
return;
}
Console.WriteLine("Reading list of students...");
Console.Write("Path and/or name of list file to read >>> ");
filePath = Console.ReadLine();
StreamReader fileToRead;
Student[] studentList;
int index = 0;
int studentCounter = 0;
List<Student> selection = new List<Student>();
try
{
fileToRead = new StreamReader(@filePath);
studentCounter = fileToRead.ReadToEnd().Split('\n').Length;
fileToRead = new StreamReader(@filePath);
studentList = new Student[studentCounter - 1];
while (fileToRead.EndOfStream != true)
{
String[] data = fileToRead.ReadLine().Split(';');
studentList[index] = new Student(data[0], data[1], Convert.ToInt16(data[2]), Convert.ToInt32(data[3]), data[4], data[5], Convert.ToInt32(data[6]));
if (studentList[index].getCourse().Equals(5) && studentList[index].getCityOfReference().Equals("Kiev"))
{
selection.Add(studentList[index]);
}
index++;
}
fileToRead.Close();
Console.WriteLine("\nList of students of 5th year of studying whose city of residence is Kiev:");
int counter = 1;
foreach (Student st in selection)
{
Console.WriteLine("[Student {0}] Name: {1} {2}, Year of studying: {3}, Student ID: {4}, Sex: {5}, City of residence: {6}, Recordbook ID: {7}\n",
counter, st.getFirstName(), st.getLastName(), st.getCourse(), st.getStudentId(), st.getSex(), st.getCityOfReference(), st.getStudentRecordbookId());
++counter;
}
}
catch (FileNotFoundException fnfEx)
{
Console.WriteLine("[ERROR] File not found: {0}", fnfEx.Message);
}
catch (IndexOutOfRangeException iorEx)
{
Console.WriteLine("[ERROR] Index out of range. Added {0} elements to array only. {1}", studentCounter, iorEx.Message);
}
catch (IOException ioEx)
{
Console.WriteLine("[ERROR] I/O Exception: {0}", ioEx.Message);
}
catch (ArgumentException argEx) {
Console.WriteLine("[ERROR] File path wasn't define: {0}", argEx.Message);
}
Console.Read();
}