You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
716 B
28 lines
716 B
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlTypes;
|
|
using System.Linq;
|
|
using System.Xml.Schema;
|
|
namespace Babushka.scripts.CSharp.Common.Util;
|
|
|
|
public static class LinqExtras
|
|
{
|
|
public static void ForEach<T>(this IEnumerable<T> self, Action<T> action)
|
|
{
|
|
foreach (var t in self)
|
|
{
|
|
action.Invoke(t);
|
|
}
|
|
}
|
|
|
|
public static T? Random<T>(this IEnumerable<T> self)
|
|
{
|
|
var selfList = self.ToList();
|
|
if (selfList.Count == 0) return default;
|
|
if (selfList.Count == 1) return selfList[0];
|
|
var randomIndex = new Random().Next(0, selfList.Count);
|
|
return selfList[randomIndex];
|
|
}
|
|
}
|