-3

I want to pass value as True if some list has value , for example here

if item.Achievements.Count() has value then i need to pass something like this

...
item.Location.City + "|" +True + "|" + item.Soid + "|" +
...

Code is like this

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);
}
default locale
  • 13,035
  • 13
  • 56
  • 62

4 Answers4

2

You can do

(.Count() > 0).toString();

Sayse
  • 42,633
  • 14
  • 77
  • 146
1

Simply use:

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);

This will call ToString() on the bool (System.Boolean) which will return either bool.TrueString or bool.FalseString.

Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181
0

replace line with:

(item.Achievements.Count() > 0) ? "true" : "false"

or better as suggested in comments if you are using .NET list

item.Achievements.Any()
taminov
  • 591
  • 7
  • 23
  • 5
    better choice would be to use item.Achievements.Any() – Michal Franc Feb 27 '13 at 10:17
  • http://stackoverflow.com/questions/305092/which-method-performs-better-any-vs-count-0 ...although to find out how much difference it makes you'd have to profile it. – Arran Feb 27 '13 at 10:18
0

Count is a property:

...
item.Location.City + "|" +
item.Achievements.Count > 0 ? "true" : "false" + "|" +
item.Soid + "|" +
...
Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162