读书人

帮小弟我看看这样设计一个用户类对不对

发布时间: 2012-01-15 22:57:49 作者: rapoo

帮我看看这样设计一个用户类对不对
这个是设计的一个用户类,代码如下:
public class pubUser
{
private int ID=0;

public string userName
{
set { this.userName = value; }//这里报错!!
get { return this.userName; }
}

public string userPass
{
set { this.userPass = value; }
get { return this.userPass; }
}

public string userRights
{
set { this.userRights = value; }
get { return this.userRights; }
}
/*
public static string userName;
public static string userPass;
public static string userEmail;
public static string userCnName;
public static string userTel;
public static string userRights;
public static string userSign;
*/
}


使用时这样
while (oReader.Read())
{
if (oReader.HasRows)
{
this.DialogResult = DialogResult.OK;
pubUser user = new pubUser();
user.userName = this.tb_userName.Text;


user.userPass = this.tb_userPass.Text;
user.userRights = oReader[ "userRights "].ToString();
//user.userRights = oReader[ "userRights "].ToString();
}
else
{
MessageBox.Show( "帐号或密码错误(E)! ");
return;
//this.DialogResult = DialogResult.Cancel;
}
}

但是出错,我怀疑是不是类设计错了,
帮忙看看,

this.userName = value;//这一行报错,提示如下
未处理的“System.StackOverflowException”类型的异常出现在 金棕榈2.exe 中。

[解决办法]
public string UserName <--这样写呢
{
set { this.userName = value;
get { return this.userName; }
}

[解决办法]
类里面做个内部变量,如 _userName
然后 _userName = value 就好了
[解决办法]
没见过你这样定义的.你是想做什么呀.你是不是做属性的呀.

private string username;
public string U_Name
{
get
{
return username;
}
set
{
username = value;
}
}

你是不是想干这个
[解决办法]
private string username;
public string U_Name
{
get
{
return username;
}
set
{
username = value;
}
}
这样做肯定没有问题啦

读书人网 >C#

热点推荐