Advertisement
Gillito

Untitled

Jun 5th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 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(name);
  24.             if (x != null)
  25.                 Console.WriteLine(x.Firstname);
  26.             else
  27.                 Console.WriteLine("Поиск не дал результата");
  28.         }
  29.     }
  30.  
  31.     class Journal
  32.     {
  33.         private List<Student> students = new List<Student>();
  34.  
  35.         public void Addstudent(string studentFname, string studentLname)
  36.         {
  37.             Student student = new Student();
  38.  
  39.             student.Firstname = studentFname;
  40.             student.Lastname = studentLname;
  41.             students.Add(student);
  42.         }
  43.  
  44.         public Student Search(string searchfirstname)
  45.         {
  46.             foreach (Student i in students)
  47.                 if (i.Firstname == searchfirstname)
  48.                     return i;
  49.             return null;
  50.         }
  51.     }
  52.  
  53.     public class Student
  54.     {
  55.        public string Firstname;
  56.        public string Lastname;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement