Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2013-05-09
1
441 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

789 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