【问题标题】:parsing a variable from class to class从一个类到另一个类解析一个变量
【发布时间】:2016-06-11 23:04:34
【问题描述】:

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

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

【问题讨论】:

  • 不清楚你在问什么。 STARTbtn_ClickGettemp 之间没有任何连接

标签: c# class variables parameter-passing


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2013-02-08
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多