Advertisement
Gillito

Untitled

Jun 5th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 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.             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.             foreach (Student i in students)
  44.                 if (i.Firstname == searchfirstname)
  45.                     return i;
  46.             return null;
  47.         }
  48.     }
  49.  
  50.     public class Student
  51.     {
  52.        public string Firstname;
  53.        public string Lastname;
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement