score:78
you don't need to use linq to get the values. the dictionary(tkey, tvalue)
has a property that holds the values, dictionary(tkey, tvalue).values
:
var fields = objdictionary.values.tolist();
score:1
with c# 7 it is possible to use tuples, which makes this conversion much simpler and you can have the both the key and the value in the list.
var mylist = new list<(tkey, tvalue)>(dic.select(x => (tkey, tvalue)));
full example
dictionary<int, string> dic = new dictionary<int, string>();
dic.add(1, "test1");
dic.add(2, "test2");
dic.add(3, "test3");
var mylist = new list<(int, string)>(dic.select(x => (x.key, x.value)));
foreach (var myitem in mylist)
{
console.writeline($"int val = {myitem.item1} string = {myitem.item2}");
}
result
int val = 1 string = test1
int val = 2 string = test2
int val = 3 string = test3
score:5
you will get a compiler error simply trying to convert a dictionary's values to a list with tolist():
dictionary<int, int> dict = new dictionary<int, int>();
var result = dict.values.tolist();
unless you include "using system.linq" in your file.
Source: stackoverflow.com
Related Query
- Convert dictionary values to list using linq
- Convert a list to a dictionary and sum up values using linq
- Convert list to dictionary using linq and not worrying about duplicates
- How to get a list of filtered values in Dictionary into a List using LINQ or Lambda?
- Convert string[] to int[] in one line of code using LINQ
- LINQ - Convert List to Dictionary with Value as List
- How to select values within a provided index range from a List using LINQ
- How to select multiple values from a Dictionary using Linq as simple as possible
- Get indexes of all matching values from list using Linq
- How do I convert from a Dictionary to a SortedDictionary using LINQ in C#?
- Using LINQ to convert a list to a CSV string
- Select distinct values from a list using LINQ in C#
- Convert DataRow to Dictionary using LINQ
- C# LINQ - convert nested dictionary to a list
- Count values in Dictionary using LINQ and LINQ extensions
- Find the Second Max in a list of values using linq c#
- Group by key and send values into list using LINQ
- Convert string array to custom object list using linq
- convert comma separated string to list using linq
- How do I combine the keys and values of a Dictionary into one List using LINQ?
- Assign values from one list to another using LINQ
- How to convert list of objects with two fields to array with one of them using LINQ
- List of Dictionary to List<Type> using Linq
- How to convert an array to a dictionary using LINQ
- How to Convert Anonymous Type to List <dynamic> using Linq to SQL in C#
- How to convert Dictionary to List with mixing of values and keys?
- Transfor List to Nested Dictionary using linq C#
- How to add list of missing values in c# list using Linq
- Cast troubles while using LINQ to filter a Dictionary by values
- C# - Convert delimited string array w/ duplicates to dictionary using LINQ
More Query from same tag
- Convert T-SQL to Fluent Linq C# with the same SQL generated output
- Can 't create extesion method for LINQ to Entities link DeleteAllOnSubmit() in LINQ to SQL
- How can I parse this string into a searchable object?
- Entity Framework eager loading navigation property causes error when using user-defined type
- Error using EF6 DbFunctions.TruncateTime comparing DateTime
- Select multiple columns from Linq query
- MongoDB C# - how to do the following
- Is there a better way to do updates in LinqToSQL?
- Linq to Compare two datatables and Filter data
- LINQ: Multi table/ join + Group by
- C# LINQ Return Generic List<T>
- Linq type conversion delegate for .First method
- List shows 4 items in debugger even if filled with exactly one element
- Faster SQL Inserts?
- Modify values before inserting through an EntityDataSource Object
- Convert Sql Query of Last 50 minutes record into Linq Query
- Linq Query Timeout Forcefully
- Linq: GroupBy, Sum and Count
- Populating a List in a Strongly Typed LINQ to Entities Query
- How to select results into an object declared within an object using LINQ/Lambda?
- Xamarin Linq insert/update Sqlite table record with generated column
- query and create objects with a one to many relationship using LINQ
- Reflection in Linq
- Rx.NET: Take until specified count or timer elapsed
- LINQ Order by question
- n number of sql intersections
- linq joining tables error
- Not able to compare two Lists using LINQ
- How to enumerate Linq results?
- Does Objective-C have List Lambda Query like C#?