4
Answers

How can I make this more simple?

I have these two methods and as you can see it is just repeated code. How can I merge these into one method and pass an object type as a parameter?
 private void addButton (string Text, Point Location, Size Size)
        {
            Button b = new Button();

            b.Name = Text;
            b.Text = Text;

            b.Location = Location;
            b.Size = Size;

            this.Controls.Add(b);
        }

        private void addLabel(string Text, Point Location, Size Size)
        {
            Label l = new Label();

            l.Name = Text;
            l.Text = Text;

            l.Location = Location;
            l.Size = Size;

            this.Controls.Add(l);
        }

Thanks in advance. =)
Answers (4)