public static void input(doctor[] dentist, doctor[] surgical, doctor[] medical, ref int dlength, ref int slength, ref int mlength) { StreamReader sr = new StreamReader(@"C:\Users\acer\Desktop\doctor.txt"); while (!sr.EndOfStream) { string line = sr.ReadLine(); String[] elements = line.Split(' '); doctor d = new doctor(elements[0], elements[1], elements[2], elements[3], elements[4], elements[5], elements[6], elements[7]); if (elements[0].Equals("dentist")) { dentist[dlength++] = d; } else if (elements[0].Equals("surgical")) { surgical[slength++] = d; } else if (elements[0].Equals("medical")) { medical[mlength++] = d; } } sr.Close(); }
static void Main(string[] args) { int choice = 0, choice1 = 0; int dlength = 0, slength = 0, mlength = 0, plength = 0; doctor[] dentist = new doctor[10]; doctor[] surgical = new doctor[10]; doctor[] medical = new doctor[10]; patient[] pat = new patient[100]; input(dentist, surgical, medical, ref dlength, ref slength, ref mlength); //output(dentist, surgical, medical, ref dlength, ref slength, ref mlength); while (choice != -1) { Console.WriteLine("==========================================="); Console.Write("1)網路挂號 2)查詢/取消挂號 -1)寫檔結束 :"); choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: Console.WriteLine(""); Console.WriteLine("請選擇科別:"); Console.WriteLine(""); Console.Write("1)牙科門診 2)一般外科 3)一般內科:"); choice1 = Convert.ToInt32(Console.ReadLine()); if (choice1 == 1) { reserve(dentist, pat, dlength, ref plength); } else if (choice1 == 2) { reserve(surgical, pat, slength, ref plength); } else if (choice1 == 3) { reserve(medical, pat, mlength, ref plength); } break; case 2: search(dentist, surgical, medical, pat, dlength, slength, mlength, plength); break; case -1: writefile(pat, plength); break; default: break; } } }