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

I see that there is a ToArray () method in the API dictionary (in the area of ​​extension classes), but when I try to use it from my Dictionary instance, it cannot see it ???

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

thanks

+4
source share
2 answers

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

Have you confirmed that System.Linq is imported?

Example:

 using System.Linq; ... public void Example() { var map = new Dictionary<string,string>(); .. var arr = map.ToArray(); } 
+16
source

You are probably planning to use .NET 2.0, which does not support extension methods. Try changing the application to target .Net 3.5

0
source

All Articles