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
Post a Comment