Witam serdecznie, próbuję i próbuję ale odpowiedzi nigdzie znaleźć nie mogę.
Mam stworzoną listę, do której dodaję studentów.
Prezentuje się to następująco:
class Student
{
private int _nrIndeksu;
private string _imie;
private string _nazwisko;
private int _rokSt;
private int _ocena1, _ocena2, _ocena3;
// Gettery i Settery
public int Indeks
{
get
{ return _nrIndeksu; }
set
{
if (value > 0)
_nrIndeksu = value;
else
Console.WriteLine("Numer indeksu nie może być mniejszy bądź równy zero!");
}
}
public string Imie
{
get
{ return _imie; }
set
{
if (value != "")
_imie = value;
else
Console.WriteLine("Musisz podać imię!");
}
}
public string Nazwisko
{
get
{ return _nazwisko; }
set
{
if (value != "")
_nazwisko = value;
else
Console.WriteLine("Musisz podać nazwisko!");
}
}
public int RokStudiow
{
get
{ return _rokSt; }
set
{
if (value > 0)
_rokSt = value;
else
Console.WriteLine("Numer roku nie może być mniejszy bądź równy zero!");
}
}
public int Ocena1
{
get { return _ocena1; }
set
{
if ((value > 0) && (value <= 4))
_ocena1 = value;
else
Console.WriteLine("Podaj prawidłową ocene!");
}
}
public int Ocena2
{
get
{ return _ocena2; }
set
{
if ((value > 0) && (value <= 4))
_ocena2 = value;
else
Console.WriteLine("Podaj prawidłową ocene!");
}
}
public int Ocena3
{
get
{ return _ocena3; }
set
{
if ((value > 0) && (value <= 4))
_ocena3 = value;
else
Console.WriteLine("Podaj prawidłową ocene!");
}
}
// Koniec Getterów i Setterów
// Konstruktor
public Student(int nrIndeksu, string imie, string nazwisko, int rokSt, int ocena1, int ocena2, int ocena3)
{
Indeks = nrIndeksu;
Imie = imie;
Nazwisko = nazwisko;
RokStudiow = rokSt;
Ocena1 = ocena1;
Ocena2 = ocena2;
Ocena3 = ocena3;
}
// Koniec konstruktora
// Wyświetlanie studenta
public void ShowStudent()
{
Console.WriteLine("Imie: ", _imie, "Nazwisko: ", _nazwisko, "Numer indeksu: ", _nrIndeksu, "Rok studiów: ", _rokSt);
}
// Koniec wyświetlania studenta
}
public class Uni
{
static List<Student> listaStudentow = new List<Student>();
static List<DopuszczalneOceny> listaDopuszczalnychOcen = new List<DopuszczalneOceny>();
// Dodawanie studena
public void DodajStudenta()
{
listaDopuszczalnychOcen.Add(new DopuszczalneOceny(2, 3, 4));
int nrIndeksu;
string imie;
string nazwisko;
int rokSt;
int ocena1, ocena2, ocena3;
Console.WriteLine("DODAWANIE NOWEGO STUDENTA\n");
Console.Write("Podaj imie: ");
imie = Console.ReadLine();
Console.Write("Podaj nazwisko: ");
nazwisko = Console.ReadLine();
Console.Write("Podaj numer indeksu: ");
nrIndeksu = Convert.ToInt32(Console.ReadLine());
Console.Write("Podaj rok studiów: ");
rokSt = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Podaj oceny: ");
Console.Write("Ocena pierwsza: ");
ocena1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Ocena druga: ");
ocena2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Ocena trzecia: ");
ocena3 = Convert.ToInt32(Console.ReadLine());
listaStudentow.Add(new Student(nrIndeksu, imie, nazwisko, rokSt, ocena1, ocena2, ocena3));
}
Wszystko działa bez problemu, tylko teraz mam pewien problem. Potrzebuję wyciągnąć Ocena1, Ocena2, Ocena3 jako inty, z listy danego studenta, który jest wyszukiwany po numerze indeksu.
Wyciągnąć studenta po numerze indeksu potrafię, robię to następująco:
// Liczenie średniej studenta
public void ObliczSrednia(int indeks)
{
listaStudentow.Find(r => (r.Indeks == indeks));
}
Tylko teraz za cholerę nie wiem jak mam wyciągnąć z listy 3 wartości, jeżeli mam już wyciągniętego studenta z listy po numerze indeksu.
Z góry uprzejmie dziękuję za pomoc.