Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I use ToList() with my KeyCollection

I'm trying to modify each value in a Dictionary. The answers about how to do that generally look like this (taken from here):

foreach (var key in myDictionary.Keys.ToList())
{
    myDictionary[key] = <some kind of new value>
}

Seemingly straightforward, but it doesn't work for me; Visual Studio underlines ToList() and says

'System.Web.UI.WebControls.QueryableDataSourceHelper.ToList(System.Linq.IQueryable, System.Type)' is inaccessible due to its protection level.

Am I doing something wrong? (Obviously yes, but what?)

like image 299
Beska Avatar asked Oct 14 '25 17:10

Beska


1 Answers

This is fixed by adding a

using System.Linq;

to the top of the .cs file.

(Jon, since you led me to the right path, if you want to post this as an answer, do so, and I'll erase this answer and give you credit.)

like image 117
Beska Avatar answered Oct 17 '25 07:10

Beska



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!