Solved

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

Posted on 2013-05-09
1
434 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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now