Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I convert a .Net Dictionary<String,SomeClassType> to a List<SomeClassType>?

Posted on 2013-05-09
1
Medium Priority
?
476 Views
Last Modified: 2013-05-09
Hi:

I have a .Net dictionary defined to be the following:

Dictionary<String, SomeClassType> foo;

Open in new window



How do I convert the "Values" portion of this to a
List<SomeClassType>?

Open in new window


I would have thought that the following would work:

var foobar = foo.Values.ToList<SomeClassType>();

Open in new window


I get the following compiler error:
Error   14 'System.Collections.Generic.Dictionary<string,SomeClassType>.ValueCollection' does not contain a definition for 'ToList' and the best extension method overload 'System.Linq.ParallelEnumerable.ToList<TSource>(System.Linq.ParallelQuery<TSource>)' has some invalid arguments      



Thanks,
JohnB
0
Comment
Question by:jxbma
1 Comment
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 1520 total points
ID: 39154236
Dictionary<string, object> dict = new Dictionary<string, object>();
var arr = dict.Select(z => z.Value).ToList();

Open in new window


or

List<Foo> arr = new List<Foo>(dict.Values);

Open in new window

0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question