Добавьте файлы проекта.
This commit is contained in:
36
CollectionUtils.cs
Normal file
36
CollectionUtils.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace First_week
|
||||
{
|
||||
internal static class CollectionUtils
|
||||
{
|
||||
public static bool IsNullOrEmpty<T>(this IEnumerable<T> collection)
|
||||
{
|
||||
return collection == null || !collection.Any();
|
||||
}
|
||||
public static List<T> ToSafeList<T>(this IEnumerable<T> collection)
|
||||
{
|
||||
return collection?.ToList() ?? new List<T>();
|
||||
}
|
||||
|
||||
public static void Shuffle<T>(this IList<T> list)
|
||||
{
|
||||
if (list == null)
|
||||
return;
|
||||
|
||||
Random rng = new Random();
|
||||
int n = list.Count;
|
||||
while (n > 1)
|
||||
{
|
||||
n--;
|
||||
int k = rng.Next(n + 1);
|
||||
T value = list[k];
|
||||
list[k] = list[n];
|
||||
list[n] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user