I am going to strike again, what is the real concept of the "key" that you do not see.
If I dared to suggest, I would say that I think that you present Dictionary<TKey, TValue> as a synonym for its contents. You have a bunch of key-value pairs - this is a dictionary, right? And here you are missing an important detail. Although you could certainly implement IDictionary<TKey, TValue> using, say, a simple KeyValuePair<TKey, TValue>[] , this would be one of the biggest advantages of having a dictionary type in the first place: quick search by key.
Even if you saved an array that sorted and used binary search to find the keys (which, by the way, would bear the cost for all the inserts), you could not compete with the hash table that Dictionary<TKey, TValue> . This implementation is not just a bunch of key-value pairs without any particular structure; structure is everything for this type. Thus, a quick selection from a group of key-value pairs (content without structure) directly to the dictionary (with very specific structuring) is actually impossible - not that the structural layout of the type really determines whether casting is possible in C # in any case ( you must observe only inheritance and a few built-in and possibly user-defined transformation types).
Think of it this way: a dictionary is a container, not a content, right? Therefore, if I have a bunch of different cookies, and I want to extract all the cookies from the chocolate chips, I could extract them each, put them in a heap, and then say: “Now this is a jug of chocolate chip cookies, right?” No, I just took out the cookies; I have a bunch, not a jug. If I want a jug of chocolate chips, then I will have to put them in one, and this will require some non-zero amount of work.
Dan tao
source share