What is Virtual's need to override one method in another class? [duplicate]

0

I'm developing a C # system and I came across an inheritance / polymorphism problem. I researched Google and Microsoft referrals, but I did not find anything that would clarify my doubts. I'm using a click event on a NavigatorToolbar object to enable a new record, but in that click , I wanted it to click on get some info from this my base class.

public partial class formToolbar : formDefault
{
    public formToolbar()
    {
        InitializeComponent();
        novo.Enabled = true;
    }
    private void novo_Click(object sender, EventArgs e)
    {
        novoRegistro();
    }
    public virtual void novoRegistro() 
    {

    }
    public void novoRegistro(string t)
    {
        MessageBox.Show(t);
    }
}

This code is where you are getting the click event, and within the novoRegistro function, it will be where I will implement the creation of a new record.

public partial class inssCadastroGui : formToolbar
{
        public inssCadastroGui()
        {
            InitializeComponent();
        }

        public override void novoRegistro()
        {
            string teste = "eu sou um parametro";
            base.novoRegistro(teste);
        }
}

And this code is where you are passing the value to the function. However, when I remove the virtual of code, it stops working. I would like to do this because I would build the database / virtual system interaction of procedures , so, through this click , on each screen I would pass the data dynamically. What is the need for this virtual to create this interaction?

    
asked by anonymous 30.07.2018 / 20:41

0 answers