C# list 提示未对out参数进行赋值
如题:总提示未对out参数进行赋值。
public void GetUserInfo(string areaId, out string resultCode, out string msg, out List<UserInfo> Uses)
{
try
{
UserInfo u1 = new UserInfo();
Uses = new List<UserInfo>();
u1.Id = "0";
u1.Name = "张三";
resultCode = "0000";
msg = "";
Uses.add(u1);
}
catch (Exception e) { resultCode = "1"; msg = e.Message; } }
提示未对out Uses 进行赋值
------解决方案--------------------
如果捕获到异常,那么进入了catch,而catch中却没有对输出参数 Uses 做任何操作,所以修改如下,放在外边
public void GetUserInfo(string areaId, out string resultCode, out string msg, out List<UserInfo> Uses)
{
Uses = new List<UserInfo>();
try
{
UserInfo u1 = new UserInfo();
u1.Id = "0";
u1.Name = "张三";
resultCode = "0000";
msg = "";
Uses.add(u1);
}
catch (Exception e) { resultCode = "1"; msg = e.Message; } }
------解决方案--------------------catch块 没有对输出Users进行任何操作
把Users初始化操作放在外面
如楼上