解析从类到类的变量

时间:2016-02-29 01:28:21

标签: c# class variables parameter-passing

我想将一个变量示例编号从一个类解析为另一个类,如下面的代码所示:

public class Gettemp // is the "public" will affect the passing of variable operation?
{
    public void temp(string temp)
    {
        temp = "123";  // things that i wanted to pass from this class 
    }
}

public partial class Form1 : Form
{
    private void STARTbtn_Click(object sender, EventArgs e)
    {        
        MessageBox.Show() // i wan to show the variables here
    }
}

1 个答案:

答案 0 :(得分:0)

如何使该方法返回临时值:

public string temp()
    {
        string temp = "123";

        return temp;  // things that i wanted to pass from this class 
    }
}

private void STARTbtn_Click(object sender, EventArgs e)
    {
        Gettemp _GetTemp = new Gettemp();

        string temp = _GetTemp.temp();

        MessageBox.Show(temp);
    }