Beispiel #1
0
        public static StudentContainer SearchBySurname(String surname, StudentContainer studentArray)
        {
            var searched = new StudentContainer();

            if (studentArray.Students != null)
            {
                var studs = studentArray.Cast <Student>().Where(s => s.LastName.ToLower().Contains(surname.ToLower())).Select(s => s);
                foreach (var st in studs)
                {
                    searched.Add(st);
                }
                return(searched);
            }
            return(new StudentContainer());
        }
Beispiel #2
0
        public static StudentContainer Search(String predicate, StudentContainer studentArray, int category)
        {
            var searched = new StudentContainer();

            if (studentArray.Students != null)
            {
                switch (category)
                {
                case 0:
                {
                    var studs = from s in studentArray.Students where s.Group.ToLower().Contains(predicate.ToLower()) select s;         //отложенное выполнение запроса
                    foreach (var st in studs)
                    {
                        searched.Add(st);
                    }
                    break;
                }

                case 1:
                {
                    var studs = (from s in studentArray.Students where s.Specialization.ToLower().Contains(predicate.ToLower()) select s).ToList();         //принудительное выполнение запроса
                    foreach (var st in studs)
                    {
                        searched.Add(st);
                    }

                    break;
                }

                case 2:
                {
                    var studs = studentArray.Cast <Student>().Where(s => s.Faculty.ToLower().Contains(predicate.ToLower())).Select(s => s);       //lambda
                    foreach (var st in studs)
                    {
                        searched.Add(st);
                    }

                    break;
                }
                }
                return(searched);
            }
            return(new StudentContainer());
        }