This is just an example i have to do a simillar thing on a much larger code , but my question is why doesn t this work? I solved my problem with a string method and return statements but why can t i use a void method with the result parameter?

private void button1_Click(object sender, EventArgs e)
        {
           Method(textBox1.Text);

        }
        public  void  Method(string c)
        {
        string a = "4";
        string b = "3";
        c = a + b;

        }

Sorry, I don't understand what you really want to do exacly.

Edited 3 Years Ago by homeboy

So i have a void method where you have to concetenate "add 4 and 3" and the result is c=43
and i want the textbox to become the c . So upon clicking the button i want to get in my textbox 43

c is a local variable, it doesn't exist outside the method. What is happening is you are passing in a string (the textbox) then changing what c is referencing, not the value that it is referencing. This has no effect on the Textbox reference.

Returning a value is the prefered method, it's bad design otherwise :) If you really must do it this way, look up the 'ref' keyword on MSDN.

Edited 3 Years Ago by Momerath

Try

    private void button1_Click(object sender, EventArgs e)
    {
        Method(textBox1);
    }
    public void Method(TextBox t)
    {
        string a = "4";
        string b = "3";
        t.Text = a + b;
    }

or

    private void button1_Click(object sender, EventArgs e)
    {
        Method();
    }
    public void Method()
    {
        string a = "4";
        string b = "3";
        textBox1.Text = a + b;
    }

Edited 3 Years Ago by tinstaafl

This question has already been answered. Start a new discussion instead.