What is the most efficient way of turning the list of values of a dictionary into an array?
For example, if I have a Dictionary
where Key
is String
and Value
is Foo
, I want to get Foo[]
I am using VS 2005, C# 2.0
To convert a dictionary to an array in Python, use the numpy. array() method, and pass the dictionary object to the np. array() method as an argument and it returns the array.
You cannot use string indexes in arrays, but you can apply a Dictionary object in its place, and use string keys to access the dictionary items. The dictionary object has the following benefits when compared with arrays: The size of the Dictionary object can be set dynamically.
In Python, we can have a list or an array of dictionaries. In such an object, every element of a list is a dictionary. Every dictionary can be accessed using its index.
// dict is Dictionary<string, Foo> Foo[] foos = new Foo[dict.Count]; dict.Values.CopyTo(foos, 0); // or in C# 3.0: var foos = dict.Values.ToArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With