从一个类解析到另一个类的变量

本文关键字:另一个 变量 一个 | 更新日期: 2023-09-27 18:36:42

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

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
    }
}

从一个类解析到另一个类的变量

让该方法返回临时值怎么样:

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);
    }