Tablice dodawanie nowej wartości.

0

Witam, uczę się od niedawna C sharpa i potrzebuję zrobić program, który działka jak ten ale dodatkowo musi dać możliwość wpisania nowego studenta do listy.. I właśnie nie mam pojęcia jak to zrobić.

   class Program
    {
        struct Student
        {
            public string nazwisko;
            public string imie;
            public string kierunek;
            public int wiek;
            public double numer_indeksu;
        }
        static void Main(string[] args)
        {
            int n,n_2;
            Console.WriteLine("podaj ilosc Studentów");
            n = int.Parse(Console.ReadLine());

            if (n > 10) Console.WriteLine("za dużo studentów");
            else
            {
                Student[] a = new Student[n];

                for (int i = 0; i < a.Length; i++)
                {
                    Console.WriteLine("Podaj nazwisko");
                    a[i].nazwisko = Console.ReadLine();
                    Console.WriteLine("Podaj imie");
                    a[i].imie = Console.ReadLine();
                    Console.WriteLine("Podaj kierunek");
                    a[i].kierunek = Console.ReadLine();
                    Console.WriteLine("Podaj wiek");
                    a[i].wiek = int.Parse(Console.ReadLine());
                    Console.WriteLine("Podaj numer indeksu");
                    a[i].numer_indeksu =double.Parse(Console.ReadLine());
                    Console.Clear();
                }

                Console.WriteLine("oto lista studentów");
                foreach (Student v in a)
                {
                    Console.WriteLine("imię: {0} nazwisko: {1} kierunek: {2} wiek: {3} numer indeksu {4}", v.nazwisko, v.imie, v.kierunek, v.wiek, v.numer_indeksu);
                }
                Console.WriteLine();

                Console.Write("Wpisz nazwisko poszukiwanego studenta: ");
                string naziwsko_st = Console.ReadLine();

                foreach (Student v in a)
                {
                    if (v.nazwisko == naziwsko_st)
                    {
                        Console.WriteLine("Dane szukanego studenta:");
                        Console.WriteLine("imię: {0} nazwisko: {1} kierunek: {2} wiek: {3} numer indeksu {4}", v.nazwisko, v.imie, v.kierunek, v.wiek, v.numer_indeksu);
                    }
                }
                Console.WriteLine();

                Console.WriteLine("ilu studentów chcesz wpisac?, pamiętaj że nie możesz wpisać więcej niż {0}",10-n);
                n_2 = int.Parse(Console.ReadLine());
                if (n_2 + n > 10) Console.WriteLine("za duża liczba studentów do wpisania");
                else
                {
                    Console.WriteLine("Co tutaj wpisać ??");
                }

            }

        Console.ReadLine();
        }
    }
}
1

Zmiast struktury użyj klasy Student a studentów umieszczaj w List<Student>
https://docs.microsoft.com/pl-pl/dotnet/api/system.collections.generic.list-1?view=netframework-4.7.2
Klasa List<T> ma wyszukiwanie , sortowanie , dodawanie , usuwanie i co najważniejsze zwiększa dynamicznie w miarę potrzeby swój rozmiar.
Struktury są kopiowane przez wartość dlatego powinny mieć niewielki rozmiar np. Punkt itp.

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