Cannot apply indexing with[] to an expression of type method group

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I´m getting the above error with following lines of code:

SortedList<int, int> preparedConcepts = prepareConcepts(docs);
IList<int> preparedKeys = preparedConcepts.Keys;
foreach (int key in preparedKeys)
{
int count = prepareConcepts[key];
if (minThreshold_ > count || maxThreshold_ < count)
uselessConcepts_.Add(key);

}

but I cannot really find the error in my code.
It must be in line:
prepareConcepts[key];

In other ways it is possible to work with an index of int in a
SortedList. Why I´m getting this error here?


Regards,

Martin
 
Martin,

You're trying to use an array accessor ([]) with a method,
prepareConcepts(). prepareConcepts returns an object of type group,
hence your error.

I would recommend this:

SortedList<int, int> preparedConcepts = prepareConcepts(docs);
foreach (KeyValuePair<int, int> pairNext in preparedConcepts)
{
int count = pairNext.Value;
...
uselessConcepts_.Add(pairNext.Key);
}

That makes better use of SortedList functionality without a whole lot
of throwing around collections you don't need.

Short of that, fix your typo:

int count = prepareConcepts[key];

should be

int count = preparedConcepts[key];



Stephan
 
Martin said:
Hello,

I´m getting the above error with following lines of code:

SortedList<int, int> preparedConcepts = prepareConcepts(docs);
IList<int> preparedKeys = preparedConcepts.Keys;
foreach (int key in preparedKeys)
{
int count = prepareConcepts[key];
if (minThreshold_ > count || maxThreshold_ < count)
uselessConcepts_.Add(key);

}

but I cannot really find the error in my code.
It must be in line:
prepareConcepts[key];

In other ways it is possible to work with an index of int in a
SortedList. Why I´m getting this error here?

It looks like you have a typo:

int count = prepareConcepts[key]

should be

int count = preparedConcepts[key]

You seem to have omitted the 'd' from preparedConcepts

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top