views:

168

answers:

2

Hi,

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

+14  A: 

The Dicitonary<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();
}
JaredPar
thanks - how come VS2008 wouldn't offer me a way to "resolve" this and add the "using" line for me?
Greg
@Greg, resolving imports for extension methods is a bit more work than resolving types. It's usually on the list but cost usually causes it to not make it.
JaredPar
A: 

You're probably targeting .NET 2.0, which doesn't support Extension methods. Try changing your application to target .Net 3.5

Alan
was already targeting 3.5
Greg