DotRecastNetSim/src/DotRecast.Core/CollectionExtensions.cs

32 lines
644 B
C#
Raw Normal View History

2023-03-14 08:02:43 +03:00
using System;
using System.Collections.Generic;
2023-03-16 19:09:10 +03:00
namespace DotRecast.Core
{
2023-03-14 08:02:43 +03:00
public static class CollectionExtensions
{
public static void forEach<T>(this IEnumerable<T> collection, Action<T> action)
{
foreach (var item in collection)
{
action.Invoke(item);
}
}
public static void Shuffle<T>(this IList<T> list)
{
Random random = new Random();
int n = list.Count;
while (n > 1)
{
n--;
int k = random.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
2023-03-16 19:09:10 +03:00
}
2023-03-14 08:02:43 +03:00
}