xofz
xofz

Reputation: 5660

Visual Studio 2008 SP1:

'X', here, is a 3rd-party component implementing ICollection, and 'Y' is Count. It compiles, temporarily removing the squigglies, and either shortly after (1-2 seconds), or after any edits are made in the text editor, shows red squigglies under Count. ?! Any help would be mucho appreciated, thx.

edit: for example,

ThirdPartyComponent instanceOfComponent = new instanceOfComponent();
instanceOfComponent.GetResults();

for(int i = 0; i < instanceOfComponent.Results.Count; ++i) {
    // Some stuff happens
}

Here 'Count' is squigglied, even though it compiles fine--and even shows up in Intellisense.

Upvotes: 1

Views: 209

Answers (3)

Ali Shafai
Ali Shafai

Reputation: 5161

You need to add:

using system.linq;

Upvotes: -1

lc.
lc.

Reputation: 116438

From your comment above, it looks like VS is complaining about ambiguity between Results.Count and Results.Count(). It will compile fine, but it is warning you about this possible error. A cast to ICollection will explicitly tell the compiler which one to use:

for(int i = 0; i < ((ICollection)instanceOfComponent.Results).Count; ++i)

Upvotes: 3

ChrisBD
ChrisBD

Reputation: 9209

I'm not sure what language you're using, but two possible problems here:

  1. Count could be a function rather than a property.

  2. More likely Results is actually a property returning a List<> based class and so you are calling the Count property of this Results object rather than the instanceOfComponent. A simple cast should solve it.

Upvotes: 0

Related Questions