Добавьте файлы проекта.

This commit is contained in:
zcher
2025-12-14 18:05:36 +03:00
committed by yato
parent 64b6e01512
commit 84abc28e16
7 changed files with 228 additions and 0 deletions

36
CollectionUtils.cs Normal file
View 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;
}
}
}
}