-1

I have an observable collection and I'm trying to count the number of objects where "IsActive" = true. This looks like it should work, but I get an error saying "Count can't be used as a method". Anyone know how to do this?

int count = createAndDisplayViewModel.AvailableMonitorsForAddOC.Count(p => p.IsActive);
fubo
  • 44,811
  • 17
  • 103
  • 137
nikotromus
  • 1,015
  • 16
  • 36
  • 3
    Have you added `using System.Linq;` in the top of the file? – Thorkil Holm-Jacobsen Sep 19 '18 at 11:28
  • Son of a gun. That's it. sheesh a little intellisense help would have been nice. ;-) Thank you!!! – nikotromus Sep 19 '18 at 11:33
  • May we have an [MCVE]? Or every information you can give: What is the type of AvailableMonitorsForAddOC ? Is Count in the list of Itelisense suggestion? Could it be a Typo? Is Linq included? What is the target framwork ? – Drag and Drop Sep 19 '18 at 11:33
  • 1
    This can be solve by your fellow [light bulb](https://learn.microsoft.com/en-us/visualstudio/extensibility/walkthrough-displaying-light-bulb-suggestions?view=vs-2017) – Drag and Drop Sep 19 '18 at 11:44

1 Answers1

4

You are missing using System.Linq in the top of the file.

The misleading error message ("Count can't be used as a method") is given because the collection has a Count property, and it does not know about the extension method.

Thorkil Holm-Jacobsen
  • 7,287
  • 5
  • 30
  • 43