试图在一个类中有一个方法,但我在设置它时遇到了麻烦。尝试设置一个将字符串appstatus
保存到的字符串方法,appstatus
但首先必须为其设置值。我想最终将值设置为appstatus
来自 sql 查询并稍后在我的列表中访问它们
public class SampleData
{
public SampleData()
{
}
public string name { get; set; }
public string phoneNbr { get; set; }
public string appstatus
{
get
{
return appstatus;
}
set
{
switch (appstatus)
{
case "A":
appstatus= "Yes";
break;
case "B":
appstatus= "No";
break;
case "E":
appstatus= "Need More Info";
break;
default:
appstatus= ("Unknown");
break;
}
}
}
...using (SqlDataReader read = cmd.ExecuteReader())
{
while (read.Read())
{
try
{
SampleData d1 = new SampleData();
d1.name = Convert.ToString(read["..."]);
d1.phoneNbr = Convert.ToString(read["..."]);
d1.appstatus = (Convert.ToString(read["..."]).Trim());
list.Add(d1);
}
}
}