How can I retrieve first n elements from Dictionary<string, int> in C#? -


Is there a way to retrieve the N elements before a dictionary in C #?

Note that there is no explicit order for dictionary , however The following code is n item, there is no guarantee that what framework will be determined which n item is returned.

  using System.Linq; YourDictionary.Take (n);  

Code above IEnumerable & lt; KeyValuePair & lt; TKey, TValue & gt; & Gt; Returns containing n items. You can easily make it a dictionary & lt; TKey, TValue & gt; can change like:

  yourDictionary.Take (n). ToDictionary ();  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -