am i overloading this function properly?

  • Thread starter Thread starter CCLeasing
  • Start date Start date
C

CCLeasing

Here is my code

private void updateticks(TextBox textbox, CheckBox tickbox)
{
if (textbox.Text.Length > 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}
private void updateticks(ComboBox combox, CheckBox tickbox)
{
if (combox.Text.Length > 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}

-
It works and i can send either a textbox control, or a combobox control
as the first argument. But written like this they look like two
different functions, is there another way of writing to the above to
make it more obvious that they are the same function just overloaded?
 
This is how overloading works. You could however change it to one method like:

private void updateticks(Control control, CheckBox tickbox)
{
if (control.Text.Length > 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}

as Text is inherited from Control.
If you want it overloaded then a region around it can help with the look of
the code view

HTH

Ciaran O'Donnell
 
Ciaran said:
This is how overloading works. You could however change it to one method like:

private void updateticks(Control control, CheckBox tickbox)
{
if (control.Text.Length > 0)
{
tickbox.Visible = true;
}
else
{
tickbox.Visible = false;
}
}

Technically, this is not an overload. You are just combining two
methods into one. An overload is where you have several methods with
the same name but different arguments. The OP code is an overload, but
not necessary since your code should work.
 
I'm aware of the definition of overloading, but the question was how to make
it look more like one function so I was simply informing that it can be one
function.

Ciaran O'Donnell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top