Collections extensions
List
Random
// gets an random element of the list
var randomElement = myList.Random();
var randomElement = myList.Random(System.Random random); // using System.Random
// gets element of a list with a luck factor
var randomElement = myList.Random((i, element) => element.luck);
var randomElement = myList.Random((i, element) => element.luck, System.Random random); // using System.Random
IDictionary
RemoveAll
RemoveAll using a selector
myDictionary.RemoveAll(keyValue => keyValue.Value == null);
Contains
Contains using a selector
myDictionary.Contains(keyValue => ...);
TryGetValue
TryGetValue using a selector
KeyValuePair<int, int> v;
if (myDictionary.TryGetValue(keyValue => keyValue.Key > 10, out v)) {
return v;
}
FirstOrNull
FirstOrNull using a selector. Returns a System.Nullable
var v = myDictionary.FirstOrNull(keyValue => keyValue.Key > 10, out v);
if (v.HasValue) {
return v.Value.Value;
}