C#中关于struct的问题,百思不得其解?????

feeling_vb 2003-05-24 06:43:16
namespace CRM_LANDSERVER.classPackage
{

public struct UserDataRight
{
public bool UserDelRight; //删除权限
public bool UserSelRight ; //查询权限
public bool UserAddRight; //新增权限
public bool UserEditRight; //编辑权限
public bool UserSaveRight; //保存权限
}


public class UserCharacter
{
protected string strUserID;
public UserCharacter()
{

}
public UserCharacter(string UserID)
{
this.strUserID=UserID;

}

public void UserValRight(out UserDataRight userDataRight){
try
{
//此处连接数据库部分省略 SqlDataReader userGroupRecord=cmdUserRight.ExecuteReader();
//初始化权限
userDataRight.UserAddRight=false;
userDataRight.UserDelRight=false;
userDataRight.UserEditRight=false;
userDataRight.UserSaveRight=false;
userDataRight.UserSelRight=false;
while(userGroupRecord.Read()){
//判断是否有查询权限
if(userGroupRecord.GetValue(3).ToString()=="1"){
userDataRight.UserSelRight=true;
}

}
userGroupRecord.Close();

}

catch(SqlException sqlE){
MessageBox.Show("数据库连接错误!"+sqlE.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}catch(Exception e){MessageBox.Show("异常错误!"+e.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}



}


}

////////////////////调用部分的代码是

UserCharacter userRightCharacter=new UserCharacter("001");
UserDataRight userDataRights;
userDataRights=new UserDataRight();
userRightCharacter.UserValRight(out userDataRights);
if(userDataRights.UserSelRight==true)
{
MessageBox.Show("有新增权限");
}else{
MessageBox.Show("sdddd");
}


////////////////////
错误是E:\CRM\CRM_LANDSERVER\classPackage\UserCharacter.cs(50): The out parameter 'userDataRight' must be assigned to before control leaves the current method

...全文
28 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yqdeng 2003-05-24
  • 打赏
  • 举报
回复
public void UserValRight(out UserDataRight userDataRight){
try
{
//此处连接数据库部分省略 SqlDataReader userGroupRecord=cmdUserRight.ExecuteReader();
//初始化权限

usetDataRight = new UserDataRight();//add this sentence

userDataRight.UserAddRight=false;
userDataRight.UserDelRight=false;
userDataRight.UserEditRight=false;
userDataRight.UserSaveRight=false;
userDataRight.UserSelRight=false;
while(userGroupRecord.Read()){
//判断是否有查询权限
if(userGroupRecord.GetValue(3).ToString()=="1"){
userDataRight.UserSelRight=true;
}

}
userGroupRecord.Close();

}

////////////////////调用部分的代码是

UserCharacter userRightCharacter=new UserCharacter("001");
UserDataRight userDataRights;
//userDataRights=new UserDataRight();
userRightCharacter.UserValRight(out userDataRights);
if(userDataRights.UserSelRight==true)
{
MessageBox.Show("有新增权限");
}else{
MessageBox.Show("sdddd");
}
FRtfp 2003-05-24
  • 打赏
  • 举报
回复
out 不要在调用时赋值吧
shuker 2003-05-24
  • 打赏
  • 举报
回复
就是说out参数必须在调用的时候被赋值
你可以在函数的第一句话加上userDataRight = ??;这样的赋值语句
这和struct无关的

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧