Advertisement
Gillito

Untitled

Jun 5th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication32
  8. {
  9.     public class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Journal StudentsBase = new Journal();
  14.  
  15.             Console.WriteLine("Введите имя студента: ");
  16.             string firstname = Console.ReadLine();
  17.             Console.WriteLine("Введите фамилию: ");
  18.             string lastname = Console.ReadLine();
  19.  
  20.             StudentsBase.Addstudent(firstname, lastname);
  21.             Console.WriteLine("кого искать?");
  22.             string name = Console.ReadLine();
  23.             Student x = StudentsBase.Search(firstname);
  24.             Console.WriteLine(x.Firstname);
  25.         }
  26.     }
  27.  
  28.     class Journal
  29.     {
  30.         private List<Student> students = new List<Student>();
  31.  
  32.         public void Addstudent(string studentFname, string studentLname)
  33.         {
  34.             Student student = new Student();
  35.  
  36.             student.Firstname = studentFname;
  37.             student.Lastname = studentLname;
  38.             students.Add(student);
  39.         }
  40.  
  41.         public Student Search(string searchfirstname)
  42.         {
  43.             Student stud;
  44.             stud = new Student();
  45.            
  46.             foreach (Student i in students)
  47.             {
  48.                 if (i.Firstname == searchfirstname) //|| i.lastname == searchlastname)
  49.                 {
  50.                     stud = i;
  51.                     break;
  52.                 }
  53.                 else
  54.                     Console.WriteLine("Поиск не дал результата.");
  55.             }
  56.             return stud;
  57.         }
  58.     }
  59.  
  60.     public class Student
  61.     {
  62.        public string Firstname;
  63.        public string Lastname;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement