Это лучший способ написать код для двух классов, я был бы признателен за обратную связь, заранее спасибо
***
private string ime; private string prezime; private string smer; private string pol; private static int godRodjenja; public string Ime { get => ime; set => ime = value; } public string Preime { get => prezime; set => prezime = value; } public string Smer { get => smer; set => smer = value; } public string Pol { get => pol; set => pol = value; } public int GodRodjenja { get => godRodjenja; set => godRodjenja = value; } public Student(string ime1, string prez2, string smr, string p, int gr) { ime = ime1; prezime = prez2; smer = smr; pol = p; gr = godRodjenja; } public Student() { ime = ""; prezime = ""; smer = ""; pol = ""; godRodjenja = 0; } public override string ToString() { return "Ime i prezime: " + ime + prezime + "Pol" + pol + "Godina rodjenja:" + godRodjenja + "Smer" + smer; } } } **** class Podaci:Student { private string adresa; private string email; public string Adresa { get => adresa; set => adresa = value; } public string Email { get => email; set => email = value; } public Podaci(string ime1, string prez2, string smr, string p, int gr,string adre, string ema):base(ime1, prez2, smr, p,gr) { adresa = adre; email = ema; } public override string ToString() { return Ime + Preime + Smer + Pol + GodRodjenja + Adresa + Email; } }
*******
Что я уже пробовал:
public partial class frmUnosStudenta : Form { public Student stud; public frmUnosStudenta() { InitializeComponent(); } private void button3_Click(object sender, EventArgs e) { Close(); } private void button2_Click(object sender, EventArgs e) { textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); ResetText(); } private void button1_Click(object sender, EventArgs e) { string ime = textBox1.Text; string prezime = textBox2.Text; string smer = comboBox1.Text; string pol = ""; if (radioButton1.Checked == true) { pol = "Muski"; } if(radioButton2.Checked==true) { pol = "Zenski"; } int godRodjenja = Convert.ToInt16(textBox3.Text) ; stud = new Student(ime,prezime,smer,pol, godRodjenja); DialogResult = DialogResult.OK; if (textBox1.Text == string.Empty) { errorProvider1.SetError(textBox1, "Unesite nesto!"); textBox1.SelectAll(); textBox1.Focus(); } if (comboBox1.Text == string.Empty) { errorProvider1.SetError(textBox1, "Unesite nesto!"); textBox1.SelectAll(); textBox1.Focus(); } } ++++++++++++++++++ public partial class frmSkola : Form { Queue<student> ts; public frmSkola() { InitializeComponent(); ts = new Queue<student>(); } private void button1_Click(object sender, EventArgs e) { frmUnosStudenta frmUnos = new frmUnosStudenta(); frmUnos.Show(); ts.Enqueue(frmUnos.stud); listBox1.Items.Add(frmUnos.stud.ToString()); } private void button4_Click(object sender, EventArgs e) { Close(); } private void button2_Click(object sender, EventArgs e) { ts.Enqueue(stud); MessageBox.Show("Izbacili smo studenta!"); } private void button3_Click(object sender, EventArgs e) { ts.Clear(); while (ts.Count = !0) { ts.Dequeue(); } }
OriginalGriff
Это не очень хороший вопрос - мы не можем понять из этого малого, что вы пытаетесь сделать.
Помните, что мы не можем видеть ваш экран, получить доступ к вашему жесткому диску или прочитать ваши мысли - мы получаем только то, что вы печатаете для работы.
Что такое "лучшее"? Это субъективный термин, и он означает разные вещи в зависимости от того, что вы пытаетесь сделать и для чего вы пытаетесь использовать код.
И мы понятия не имеем, что вы здесь пытаетесь сделать!
Используйте виджет "улучшить вопрос", чтобы отредактировать свой вопрос и предоставить более подробную информацию.