Advertisement
Gillito

Untitled

Jun 4th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 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.             Console.WriteLine("Введите имя студента: ");
  15.             string firstname = Console.ReadLine();
  16.             Console.WriteLine("Введите фамилию: ");
  17.             string lastname = Console.ReadLine();
  18.             studentsBase.Addstudent(firstname, lastname);
  19.             Student x = studentsBase.Search(firstname, lastname);
  20.             Console.WriteLine(x);
  21.         }
  22.     }
  23.  
  24.     class Journal
  25.     {
  26.         public List<Student> students = new List<Student>();
  27.  
  28.         public void Addstudent(string studentFname, string studentLname)
  29.         {
  30.             Student student = new Student();
  31.  
  32.             student.firstname = studentFname;
  33.             student.lastname = studentLname;
  34.             students.Add(student);
  35.         }
  36.  
  37.         public Student Search(string firstname, string lastname)
  38.         {
  39.             Student stud;
  40.             stud = new Student();
  41.             foreach (Student i in students)
  42.             {
  43.                 if (i.firstname == firstname || i.lastname == lastname)
  44.                 {
  45.                     stud = i;
  46.                     Console.WriteLine(stud);
  47.                 }
  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