Advertisement
Gillito

Untitled

Jun 5th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 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 = null;
  44.             foreach (Student i in students)
  45.             {
  46.                 if (i.Firstname == searchfirstname)
  47.                     return stud = i;
  48.                 else
  49.                     Console.WriteLine("Поиск не дал результата.");
  50.             }
  51.             return stud;
  52.         }
  53.     }
  54.  
  55.     public class Student
  56.     {
  57.        public string Firstname;
  58.        public string Lastname;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement