wyszukiwanie studentów za pomocą imienia lub nazwiska

0

Mam takie zadanie:
Zadeklarować trzyelementową tablicę struktury "student" zawierającą pola: imię, nazwisko, wiek, indeks, średnia. Pobrać dane studentów od użytkownika i następnie zrobić moduł wyszukiwania studentów po imieniu lub nazwisku.

Mam już początek:

class Program
    {
        struct Student
        {
            public String imie;
            public String nazwisko;
            public int indeks;
            public double średnia;
            public double wiek;
        }
        static void Main(string[] args)
        {

            int indeksPoczatkowy = 1000;
            Student[] pierwszy = new Student[3];
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine("Student {0}:", i + 1);
                Console.Write("imię: ");
                pierwszy[i].imie = Console.ReadLine();
                Console.Write("nazwisko: ");
                pierwszy[i].nazwisko = Console.ReadLine();
                Console.Write("wiek: ");
                pierwszy[i].wiek = Convert.ToDouble(Console.ReadLine());

                pierwszy[i].indeks = indeksPoczatkowy + i;
                Console.Write("średnia: ");
                pierwszy[i].średnia = Convert.ToDouble(Console.ReadLine());

            }

            Console.Clear();
            Console.WriteLine("Studenci:");
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine("{0} {1} wiek: {2}; indeks: {3}; średnia: {4}", pierwszy[i].imie, pierwszy[i].nazwisko, pierwszy[i].wiek, pierwszy[i].indeks, pierwszy[i].średnia);
            }

nie wiem jak opracować moduł, proszę o pomoc

0
Student GetStudentByName(string name)
{
   return pierwszy.First(s=>s.imie == name);
}

Zwraca pierwszy element który znajdzie.

1
   class Program
    {
        struct Student
        {
            public String imie;
            public String nazwisko;
            public int indeks;
            public double średnia;
            public double wiek;
        }        

        static void Main(string[] args)
        {

            int indeksPoczatkowy = 1000;
            Student[] pierwszy = new Student[3];
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine("Student {0}:", i + 1);
                Console.Write("imię: ");
                pierwszy[i].imie = Console.ReadLine();
                Console.Write("nazwisko: ");
                pierwszy[i].nazwisko = Console.ReadLine();
                Console.Write("wiek: ");
                pierwszy[i].wiek = Convert.ToDouble(Console.ReadLine());

                pierwszy[i].indeks = indeksPoczatkowy + i;
                Console.Write("średnia: ");
                pierwszy[i].średnia = Convert.ToDouble(Console.ReadLine());

            }

            Console.Clear();
            Console.WriteLine("Studenci:");
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine("{0} {1} wiek: {2}; indeks: {3}; średnia: {4}", pierwszy[i].imie, pierwszy[i].nazwisko, pierwszy[i].wiek, pierwszy[i].indeks, pierwszy[i].średnia);
            }

            Console.WriteLine();
            Console.WriteLine("Wpisz nazwisko studenta: ");
            string nazwiskoStudenta = Console.ReadLine();

            foreach (Student student in pierwszy)
            {
                if (student.nazwisko == nazwiskoStudenta)
                {
                    Console.WriteLine("Dane szukanego studenta:");
                    Console.WriteLine("Imie: " + student.imie + ", nazwisko: " + student.nazwisko + ", wiek: " + student.wiek + ", indeks: " + student.indeks + ", średnia: " + student.średnia);
                }
            }
        }
        
    }
0

a jak zrobić, żeby użytkownik mógł wybrać czy chce wyszukiwać po imieniu czy po nazwisku?

1
   Console.WriteLine();
            bool IsIncorect = true;
            string i = "";
            while(IsIncorect)
            {
            Console.WriteLine("Wciśnij 1 jeśli chcesz szukać po imieniu lub 2 jeśli po nazwisku ");
            i = Console.ReadLine();
            if(i = "1")
            {
               i = "imie";
               IsIncorect = false;
            }
            if(i = "2")
             {
               i = "nazwisko";
               IsIncorect = false;
             }
            else
              Console.WriteLine("Zły wybór");
              }
            Console.WriteLine("Wpisz {0} studenta: ", i);
            string parametr = Console.ReadLine();

                if (i == imie)
                {
                   try
                    {
                    Student student = pierwszy.First(p=>p.Imie == parametr);
                    Console.WriteLine("Dane szukanego studenta:");
                    Console.WriteLine("Imie: " + student.imie + ", nazwisko: " + student.nazwisko + ", wiek: " + student.wiek + ", indeks: " + student.indeks + ", średnia: " + student.srednia);
                    }
                    catch
                     Console.WriteLine("Nie istnieje student o podanym imiemiu");
                }
                if (i == nazwisko)
                {
                  try
                    {
                    Student student = pierwszy.First(p=>p.Nazwisko == parametr);
                    Console.WriteLine("Dane szukanego studenta:");
                    Console.WriteLine("Imie: " + student.imie + ", nazwisko: " + student.nazwisko + ", wiek: " + student.wiek + ", indeks: " + student.indeks + ", średnia: " + student.srednia);
                    }
                    catch
                     Console.WriteLine("Nie istnieje student o podanym nazwisku");
                }    
            

Może coś takiego.

1 użytkowników online, w tym zalogowanych: 0, gości: 1