当前位置:编程学习 > C#/ASP.NET >>

怎么传递字符串。。。。急!!!

 怎么把info里面的 a 传到 button1里面,代码如下:

public partial class info : Form
    {   
         
        public info()
        {
            
            InitializeComponent();
            string a="guo";
        }
 private void button1_Click(object sender, EventArgs e)
        {    
           string b=a;
         } --------------------编程问答--------------------

public partial class info : Form
{   

public info()
{
InitializeComponent();
a = "guo";
}
private string a = "";
private void button1_Click(object sender, EventArgs e)
{   
string b=a;
MessageBox.Show(b);
}
}
--------------------编程问答-------------------- 顶起。。。。。。。 --------------------编程问答-------------------- public string a="guo";

private void button1_Click(object sender, EventArgs e)
  {   
  string b=a;
  } --------------------编程问答-------------------- button1.text = a; --------------------编程问答--------------------
public partial class info : Form
{   

    public info()
    {
        InitializeComponent();
        button1.Tag = "guo";
    }

    private void button1_Click(object sender, EventArgs e)
    {   
        string b=button1.Tag.ToString();
        MessageBox.Show(b);
    }
}
--------------------编程问答-------------------- 变量在方法里访问不到 --------------------编程问答--------------------
引用 1 楼 wuyazhe 的回复:
C# code

public partial class info : Form
{   

    public info()
    {
        InitializeComponent();
        a = "guo";
    }
    private string a = "";
    private void button1_Click(obj……


对,用全局变量 --------------------编程问答-------------------- string a应设为类变量:

public partial class info : Form
  {   
  string a=null;
  public info()
  {
    
  InitializeComponent();
  string a="guo";
  }
 private void button1_Click(object sender, EventArgs e)
  {   
  string b=a;
  } --------------------编程问答-------------------- 路过,学习。 --------------------编程问答-------------------- --------------------编程问答-------------------- 一楼的值得一看 --------------------编程问答-------------------- 这个难 顶一下 --------------------编程问答-------------------- 汗,变量的使用范围还没搞明白 --------------------编程问答--------------------
引用楼主 gt138138 的回复:
怎么把info里面的 a 传到 button1里面,代码如下:

public partial class info : Form
  {  
     string a="guo";//这个弄到外面做全局即可
  public info()
  {
  InitializeComponent();
  }
 private void button1_Click(object sender,……
--------------------编程问答-------------------- 谢谢大家啦
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,