Abhilash JA Abhilash JA - 25 days ago 5
C# Question

If list object is zero then set another value

I have a 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();


From this list, when Id is 0 then assign UserType="UnKnown".

How can I do that?

Answer

Replace

UserType = "Documents Scanned" 

with

UserType = m.UserId != 0 ? "Documents Scanned" : "UnKnown"