Core/Refactor: Part 3
This commit is contained in:
@@ -66,6 +66,9 @@ namespace System.Collections.Generic
|
||||
}
|
||||
public static KeyValuePair<TKey, TValue> Find<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key)
|
||||
{
|
||||
if (!dict.ContainsKey(key))
|
||||
return default(KeyValuePair<TKey, TValue>);
|
||||
|
||||
return new KeyValuePair<TKey, TValue>(key, dict[key]);
|
||||
}
|
||||
|
||||
@@ -113,17 +116,17 @@ namespace System.Collections.Generic
|
||||
}
|
||||
}
|
||||
|
||||
public static void RandomResize<T>(this ICollection<T> list, Predicate<T> predicate, uint size)
|
||||
public static void RandomResize<T>(this List<T> list, Predicate<T> predicate, uint size)
|
||||
{
|
||||
List<T> listCopy = new List<T>();
|
||||
foreach (var obj in list)
|
||||
if (predicate(obj))
|
||||
listCopy.Add(obj);
|
||||
for (var i = 0; i < list.Count; ++i)
|
||||
{
|
||||
var obj = list[i];
|
||||
if (!predicate(obj))
|
||||
list.Remove(obj);
|
||||
}
|
||||
|
||||
if (size != 0)
|
||||
listCopy.Resize(size);
|
||||
|
||||
list = listCopy;
|
||||
list.Resize(size);
|
||||
}
|
||||
|
||||
public static T SelectRandom<T>(this IEnumerable<T> source)
|
||||
|
||||
Reference in New Issue
Block a user