我有一个List,
List<Model.UserSetUp> objUserSetUp = objUserSetUp1.Select(m => new Model.UserSetUp()
{
Id = m.UserId,
FirstName = m.FirstName,
SurName = m.SurName,
Computer_Name = m.Computer_Name,
IP_Address = m.IP_Address,
LogInTime = m.LogInTime,
UserName = Decrypt(m.UserName),
Password = Decrypt(m.Password),
login_Id = m.login_Id,
UserType = "Documents Scanned",
countID = m.docCount
}).ToList();
从此列表中,当Id为0时,则指定UserType =&#34; UnKnown&#34;。
我该怎么做?
答案 0 :(得分:3)
替换
UserType = "Documents Scanned"
与
UserType = m.UserId != 0 ? "Documents Scanned" : "UnKnown"
答案 1 :(得分:2)
List<Model.UserSetUp> objUserSetUp = objUserSetUp1.Select(m => new Model.UserSetUp()
{
Id = m.UserId,
FirstName = m.FirstName,
SurName = m.SurName,
Computer_Name = m.Computer_Name,
IP_Address = m.IP_Address,
LogInTime = m.LogInTime,
UserName = Decrypt(m.UserName),
Password = Decrypt(m.Password),
login_Id = m.login_Id,
UserType = m.UserId == 0 ? "UnKnown" :"Documents Scanned",
countID = m.docCount
}).ToList();
答案 2 :(得分:1)
设置列表时只需检查一下:
List<Model.UserSetUp> objUserSetUp = objUserSetUp1.Select(m => new Model.UserSetUp()
{
Id = m.UserId,
FirstName = m.FirstName,
SurName = m.SurName,
Computer_Name = m.Computer_Name,
IP_Address = m.IP_Address,
LogInTime = m.LogInTime,
UserName = Decrypt(m.UserName),
Password = Decrypt(m.Password),
login_Id = m.login_Id,
UserType = m.UserId == 0 ? "Unknown" : "Documents Scanned",
countID = m.docCount
}).ToList();
答案 3 :(得分:1)
答案 4 :(得分:1)
你可以使用三元运算符。
而不是
#+mygraph='svg', dev='svg',echo=FALSE,fig.height=4, fig.width=8,out.width = "400px",out.height="400px"
你可以输入
UserType = "Documents Scanned",