Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# - Why can't my Dictionary class see the ToArray() method?

I see in the API Dictionary has a ToArray() method (in the extension classes area), but when I try to use this from my Dictionary instance it can't see it???

How do I "enable" ToArray() for my Dictionary instance?

Thanks

like image 299
Greg Avatar asked Oct 08 '09 20:10

Greg


1 Answers

The Dictonary<TKey,TValue> class does not actually have a .ToArray method. There is an extension method called .ToArray which can bind to Dictionary<TKey,TValue>. But this requires that System.Linq be one of your usings.

Have you verified that System.Linq is imported?

Example:

using System.Linq;
...
public void Example() {
  var map = new Dictionary<string,string>();
  ..
  var arr = map.ToArray();
}
like image 199
JaredPar Avatar answered Sep 28 '22 07:09

JaredPar