Witam,
Zaznaczam, że uczę się programowanie i robię pierwsze kroki. Chciałem wykorzystać dziedziczenie i stworzyć prosty konsolowy program, w którym użytkownik wybierze kim jest tj, student, pracownik itp(póki co mam student). Klasa główną jest osoba, z której student ma dziedziczyć imię i nazwisko oraz dodawać numer indeksu. Nie mogę skompilować kodu, gdyż cały czas mam błąd, czy ktoś coś podpowie?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication13
{
class Student : Osoba
{
private string osoba { get; set; }
public Student(string numer_ind):base(imie,nazwisko)
{
base.Wyswietl();
Console.WriteLine(imie + " " + nazwisko + " " + numer_ind);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
Osoba osoba = new Osoba(imie, nazwisko);
{
{
while (true)
{
Console.WriteLine("Wybierz kim jesteś: n1) Pracownik n2) Muzyk n3) Student");
ConsoleKeyInfo rodzaj = Console.ReadKey();
Console.WriteLine();
if (rodzaj.KeyChar >= '1' && rodzaj.KeyChar <= '3')
{
Console.WriteLine("Podaj swoje imie: ");
string imie = Console.ReadLine();
Console.WriteLine("Podaj swoje nazwisko: ");
string nazwisko = Console.ReadLine();
Console.WriteLine("Podaj swój numer indeksu: ");
var numer_ind = Console.ReadLine();
switch (rodzaj.Key)
{
case ConsoleKey.D1:
osoba.Add(new Student(numer_ind));
break;
}
Console.WriteLine("Czy chcesz wprowadzić kolejną osobę? (t/n)");
ConsoleKeyInfo key = Console.ReadKey();
if (key.KeyChar != 't')
break;
else
{
Console.WriteLine("Nieprawidłowa osoba");
}
}
}
osoba.Wyswietl();
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication13
{
class Osoba
{
public string imie;
public string nazwisko;
public Osoba(string imie,string nazwisko)
{
this.imie = imie;
this.nazwisko = nazwisko;
}
private List<Osoba> Lista = new List<Osoba>();
public void Wyswietl()
{
foreach(Osoba osoba in this.Lista)
{
osoba.Wyswietl();
}
}
public void Wyswietl(int index)
{
Lista[index].Wyswietl();
}
public void Add(Osoba osoba)
{
Lista.Add(osoba);
}
public void Remove(int index)
{
Lista.RemoveAt(index);
}
}
}