There is a dictionary of type Dictionary(Of Integer, ObjectPool) .

  1. Is it possible to get an object from it without a foreach without knowing the key?
  2. Can I get the first or last object in the dictionary without going through the elements?

    1 answer 1

    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.

    • If not hard to bring the solution for unfortunately Linq I do not know. - Dmitry Nail
    • @ Dmitry Nail, added examples, 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 - Grundy