Solved

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

Posted on 2013-05-09
1
443 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 380 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

713 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