想要传递字符串为true是list有值
本文关键字:true list 有值 字符串 | 更新日期: 2023-09-27 18:01:16
如果某个列表有值,我想将value传递为True,例如这里
如果item.Achievements.Count()
有值,那么我需要传递这样的东西
...
item.Location.City + "|" +True + "|" + item.Soid + "|" +
...
代码是这样的
foreach (var item in mgrProfile.GetMemberProfile(context.CurrentMember.MemberProfileSoid).Projects)
{
bool isdataachivevement =
string list = item.Soid+ "|" +
item.Soid + "|" +
item.ProjectTitle + "|" +
item.Role + "|" +
item.StartDate.ToShortDateString() + "|" +
item.EndDate.value.ToShortDateString() + "|" +
item.Location.Country + "|" +
item.Location.State + "|" +
item.Location.City + "|" +
// Here is I need to pass as True// if Achievements have data, otherwise false
item.Achievements.Count() + "|" +
item.Soid + "|" +
item.Soid + "|" +
item.Soid + "|" +
item.Soid + "|" +
projectlist.Add(list);
}
你可以做
(.Count() > 0).toString();
直接使用:
string list = item.Soid+ "|" +
item.Soid + "|" +
item.ProjectTitle + "|" +
item.Role + "|" +
item.StartDate.ToShortDateString() + "|" +
item.EndDate.value.ToShortDateString() + "|" +
item.Location.Country + "|" +
item.Location.State + "|" +
item.Location.City + "|" +
item.Achievements.Any() + "|" + // <--- Here is a solution
item.Achievements.Count() + "|" +
item.Soid + "|" +
item.Soid + "|" +
item.Soid + "|" +
item.Soid + "|" +
projectlist.Add(list);
这将在bool
(System.Boolean
)上调用ToString()
,这将返回bool.TrueString
或bool.FalseString
。
Count
是一个属性:
...
item.Location.City + "|" +
item.Achievements.Count > 0 ? "true" : "false" + "|" +
item.Soid + "|" +
...
用:
(item.Achievements.Count() > 0) ? "true" : "false"
或者更好,如果你正在使用。net list
item.Achievements.Any()