am i overloading this function properly?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CCLeasing

    am i overloading this function properly?

    Here is my code

    private void updateticks(Tex tBox textbox, CheckBox tickbox)
    {
    if (textbox.Text.L ength 0)
    {
    tickbox.Visible = true;
    }
    else
    {
    tickbox.Visible = false;
    }
    }
    private void updateticks(Com boBox combox, CheckBox tickbox)
    {
    if (combox.Text.Le ngth 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?

  • Ciaran O''Donnell

    #2
    RE: am i overloading this function properly?

    This is how overloading works. You could however change it to one method like:

    private void updateticks(Con trol control, CheckBox tickbox)
    {
    if (control.Text.L ength 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
    "CCLeasing" wrote:
    Here is my code
    >
    private void updateticks(Tex tBox textbox, CheckBox tickbox)
    {
    if (textbox.Text.L ength 0)
    {
    tickbox.Visible = true;
    }
    else
    {
    tickbox.Visible = false;
    }
    }
    private void updateticks(Com boBox combox, CheckBox tickbox)
    {
    if (combox.Text.Le ngth 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?
    >
    >

    Comment

    • Chris Dunaway

      #3
      Re: am i overloading this function properly?

      Ciaran O''Donnell wrote:
      This is how overloading works. You could however change it to one method like:
      >
      private void updateticks(Con trol control, CheckBox tickbox)
      {
      if (control.Text.L ength 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.

      Comment

      • Ciaran O''Donnell

        #4
        Re: am i overloading this function properly?

        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

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

        private void updateticks(Con trol control, CheckBox tickbox)
        {
        if (control.Text.L ength 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.
        >
        >

        Comment

        Working...