Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace WindowsFormsApplication18
- {
- class Student
- {
- public String First { get; set; }
- public String Last { get; set; }
- public Int32 ID { get; set; }
- int[] scores = new int[4];
- public int[] Scores
- {
- get { return scores; }
- set { scores = value; }
- }
- public override string ToString()
- {
- return First + " " + Last + " " + ID + " " + Scores.Average();
- }
- }
- class Students<T>
- {
- public T[] GetList()
- {
- return M;
- }
- private T[] M;
- public Students(IEnumerable<T> students)
- {
- M = (T[])students;
- }
- public IEnumerator<T> GetEnumerator()
- {
- //for (int i = 0; i < M.Length; i++)
- //{
- // yield return M[i];
- //}
- return (M as IEnumerable<T>).GetEnumerator();
- }
- public Students<T> FindAll(System.Predicate<T> match)
- {
- int leng = 0;
- foreach (T k in M)
- {
- if (match(k)) leng++;
- }
- T[] a = new T[leng];
- leng = 0;
- foreach (T k in M)
- {
- if (match(k)) a[leng++] = k;
- }
- return new Students<T>(a);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Student a = new Student();
- a.First = "Daniil";
- a.Last = "Dranga";
- a.ID = 3;
- a.Scores = new int[4] { 3, 4, 5, 5 };
- Student z = new Student();
- z.First = "Ayuka";
- z.Last = "Erdneev";
- z.ID = 4;
- z.Scores = new int[4] { 3, 4, 5, 5 };
- Student[] b = new Student[2];
- b[0] = a;
- b[1] = z;
- Students<Student> mass = new Students<Student>(b);
- Students<Student> ans = mass.FindAll(x => x.ID > 3);
- Student[] l = ans.GetList();
- foreach(Student p in ans)
- {
- Console.WriteLine(p.ToString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement