Advertisement
double_trouble

students(substring)

Jun 20th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication11
  7. {
  8.     class Student
  9.     {
  10.         DateTime data;
  11.         string name;
  12.  
  13.         public Student(string _name, System.DateTime _data)
  14.         {
  15.             name = _name;
  16.             data = _data;
  17.         }
  18.  
  19.         public string Name
  20.         {
  21.             get { return name; }
  22.             set { value = name; }
  23.         }
  24.  
  25.         public DateTime Data
  26.         {
  27.             get { return data; }
  28.             set { value = data; }
  29.         }
  30.  
  31.         public override string ToString()
  32.         {
  33.             return string.Format("{0} {1}", name, data.ToString());
  34.         }
  35.     }
  36.  
  37.     class MyList
  38.     {
  39.         Student[] M;
  40.         int count;
  41.  
  42.         public MyList(ConsoleApplication11.Student[] st)
  43.         {
  44.             M = new Student[st.Length];
  45.             M = st;
  46.         }
  47.  
  48.         public int Count
  49.         {
  50.             get { return count; }
  51.             set { value = count; }
  52.         }
  53.  
  54.         public System.Collections.IEnumerable GetEnumerator()
  55.         {
  56.             for (int i = 0; i < count; i++)
  57.                 yield return M[i];
  58.         }
  59.  
  60.         public static ConsoleApplication11.MyList addList(ConsoleApplication11.MyList obj1, ConsoleApplication11.MyList obj2)
  61.         {
  62.             Student[] rez = new Student[obj1.Count + obj2.Count];
  63.             for (int i = 0; i < obj1.Count; i++)
  64.                 rez[i] = obj1.M[i];
  65.             for (int i = 0; i < obj2.Count; i++)
  66.                 rez[i + obj1.Count] = obj2.M[i];
  67.             return new MyList(rez);
  68.         }
  69.  
  70.         public ConsoleApplication11.MyList ArrayFilter(string str)
  71.         {
  72.             Student[] rez = new Student[count];
  73.             int k = 0;
  74.             for (int i =0; i<count; i++)
  75.             {
  76.                 for (int j =0; j < M[i].Name.Length - str.Length; i++)
  77.                     if (M[i].Name.Substring(j, str.Length) == str)
  78.                     {
  79.                         rez[k] = M[i];
  80.                         k++;
  81.                     }
  82.             }
  83.             Student[] r = new Student[k];
  84.             Array.Copy(rez, r, k);
  85.             return new MyList(r);
  86.         }
  87.     }
  88.  
  89.     class Program
  90.     {
  91.         static void Main(string[] args)
  92.         {
  93.            
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement