There is a dictionary of type Dictionary(Of Integer, ObjectPool) .
- Is it possible to get an object from it without a
foreachwithout knowing the key? - Can I get the first or last object in the dictionary without going through the elements?
Dictionary<TKey,TValue> implements the IEnumerable<T> interface, so you can use the Linq: First , Last, and similar methods.
For example:
Dim first As ObjectPool = dict.FirstOrDefault().Value Dim last As ObjectPool = dict.LastOrDefault().Value But since the IList<T> interface is not implemented, you cannot call by index.
Value at the end is necessary because the dictionary is IEnumerable<KeyValuePair<TKey,TValue>> , therefore, to get the value you need to take Value from the received object - GrundySource: https://ru.stackoverflow.com/questions/547178/
All Articles