class1中放一个属性字段就可以了,如: public string ID { set _id = value; get { return _id}; }或者你在构造函数中写也行:public class1(string id) { this._id = id; }然后在textbox1所在的窗体中:class1 c = new class1(textbox1.text);就可以了嘛
用一个静态类和静态字段来保存你的全域变量嘛public static class qx .........
我郁闷了 按你的方法在class1中放下面的这段代码 他妈的哪些}号就就不在那个类中了 public string ID { set _id = value; get { return _id}; } 构造函数中 写也是这个问题 我想问一下这到底是怎么回事啊 谢谢了
public string ID { get { return _id; } set { this._id=value; } }
to ptpa(古月西西) 正解
public string ID { set { _id = value; } get { return _id; } }或者你在构造函数中写也行:public class1(string id) { this._id = id; }然后在textbox1所在的窗体中:class1 c = new class1(textbox1.text);
YUAN168(仙人掌) 的方法应该能解决
可以解释一下吗 _id 老是说不存在 textbox1.text说受保护级别限制不可访问
在登陆窗体中的代码 Class1 c = new Class1(); c.t=textBox1.Text; 在class中的代码 public string t { get { return t; } set { t=value; } } 运行后就出现下面错误 未处理的“System.StackOverflowException”类型的异常出现在 WindowsApplication3.exe 中。
private string t; public string t { get { return t; } set { t=value; } } 你需要加第一句。看来C#你还没有入门啊,好好学习啊,我的代码写错了,不过别人写对了。
然后判断class1中的变量权限
button1.Visible= false;
{
public Class1(string,string)
private string ID1;
private string Role;
...
}
Form2 fm2=new Form2(new Class1("1","Admin")); fm2(Class1 cls1)
{
}
From2.Page_Load(object ...)
{
if(cls1.Role=="")
button.Visiable=false;
{
public string ID
{
set _id = value;
get { return _id};
}或者你在构造函数中写也行:public class1(string id)
{
this._id = id;
}然后在textbox1所在的窗体中:class1 c = new class1(textbox1.text);就可以了嘛
.........
public string ID
{
set _id = value;
get { return _id};
}
构造函数中 写也是这个问题 我想问一下这到底是怎么回事啊 谢谢了
{
get
{
return _id;
}
set
{
this._id=value;
}
}
正解
{
set { _id = value; }
get { return _id; }
}或者你在构造函数中写也行:public class1(string id)
{
this._id = id;
}然后在textbox1所在的窗体中:class1 c = new class1(textbox1.text);
Class1 c = new Class1();
c.t=textBox1.Text;
在class中的代码
public string t
{
get
{
return t;
}
set
{
t=value;
}
}
运行后就出现下面错误
未处理的“System.StackOverflowException”类型的异常出现在 WindowsApplication3.exe 中。
public string t
{
get
{
return t;
}
set
{
t=value;
}
}
你需要加第一句。看来C#你还没有入门啊,好好学习啊,我的代码写错了,不过别人写对了。