Exemple #1
0
        public static StudentArray Search(String predicate, StudentArray studentArray, int category)
        {
            var searched = new StudentArray();

            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.Specialty.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 StudentArray());
        }
Exemple #2
0
        public static StudentArray SearchBySurname(String surname, StudentArray studentArray)
        {
            var searched = new StudentArray();

            if (studentArray.Students != null)
            {
                var studs = studentArray.Cast <Student>().Where(s => s.Surname.ToLower().Contains(surname.ToLower())).Select(s => s);
                foreach (var st in studs)
                {
                    searched.Add(st);
                }
                return(searched);
            }
            return(new StudentArray());
        }