public List <Student> SearchStudent(string searchOption) { string Sword = null; Sword = SearchWord; string name = null; int age = 0; int course = 0; string classes = null; double avrgMrk = 0; List <Student> fndtStudent = new List <Student>(); if (searchOption.Equals("Name")) { name = SearchWord; } else if (searchOption.Equals("Class")) { classes = SearchWord; } List <Student> allStudents = ShowAllStudentsInData(); foreach (Student searchedStudnt in allStudents) { if (SearchWord.Equals("")) { fndtStudent = allStudents; } else if (name != null && name.Equals(searchedStudnt.Name)) { fndtStudent.Add(searchedStudnt); } else if (classes != null && classes.Equals(searchedStudnt.Class)) { fndtStudent.Add(searchedStudnt); } } Students = fndtStudent; return(Students); }