public static bool TryRemoveFirst <TKey, TValueList, TValue>(IDictionary <TKey, TValueList> listDictionary, TKey key, out TValue value) where TValueList : IList <TValue> { TValueList list; if (!listDictionary.TryGetValue(key, out list)) { return(Returns.False(out value)); } var count = list.Count; if (count > 0) { value = list[0]; list.RemoveAt(0); if (--count == 0) { listDictionary.Remove(key); } return(true); } else { listDictionary.Remove(key); // Error? return(Returns.False(out value)); } }
public static bool TryGetValue <TKey, TValue>(this IDictionary <TKey, List <TValue> > listDictionary, TKey key, int index, out TValue value) { List <TValue> list; if (!listDictionary.TryGetValue(key, out list)) { return(Returns.False(out value)); } if (index < 0 || index >= list.Count) { return(Returns.False(out value)); } value = list[index]; return(true); }