12345678910111213141516171819202122232425262728293031 |
- using System.Collections.Generic;
- namespace MafiaTelegramBot.CustomCollections.Extensions
- {
- public static class ListExtension
- {
- public static T GetAndRemove<T>(this List<T> list, int index)
- {
- var value = list[index];
- list.RemoveAt(index);
- return value;
- }
- public static void AddTimes<T>(this List<T> list, T item, int times)
- {
- for (var i = 0; i < times; ++i) list.Add(item);
- }
- public static List<T> Copy<T>(this List<T> list)
- {
- return new(list);
- }
- public static bool AddUnique<T>(this List<T> list, T item)
- {
- if (list.Contains(item)) return false;
- list.Add(item);
- return true;
- }
- }
- }
|