I have a dictionary in C#:
public Dictionary
And I would like to get my result in to a generic list:
Li
Here's an example using LINQ query syntax.
public class TestDictionary
{
public void Test()
{
Dictionary dict=new Dictionary();
dict.Add(new Product(){Data = 1}, 1);
dict.Add(new Product() { Data = 2 }, 2);
dict.Add(new Product() { Data = 3 }, 3);
dict.Add(new Product() { Data = 4 }, 9);
dict.Add(new Product() { Data = 5 }, 5);
dict.Add(new Product() { Data = 6 }, 6);
var query=(from c in dict
orderby c.Value descending
select c.Key).ToList();
}
[DebuggerDisplay("{Data}")]
public class Product
{
public int Data { get; set; }
}
}