Advertisement
StoneHaos

Untitled

Aug 6th, 2021 (edited)
1,183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Threading.Tasks;
  6. using System.Security.Cryptography;
  7. using System.Text;
  8. using Newtonsoft.Json;
  9. using System.Xml;
  10.  
  11.  
  12. namespace Test {
  13.     class Program {
  14.  
  15.         public static void Div(ref List<int> lst, int mod) {
  16.             int removeCount = lst.Count - (lst.Count / mod);
  17.             for (int i = lst.Count - removeCount; i < lst.Count; ++ i) {
  18.                 //Здесь происходит с удаляемыми объектами, если нужно
  19.                 //Например:
  20.                 //Destroy(lst[i])
  21.             }
  22.             lst.RemoveRange(lst.Count - removeCount, removeCount);
  23.         }
  24.  
  25.         public static void Main() {
  26.             int n = 10;
  27.             List<int> lst = new List<int>();
  28.             for (int i = 0; i < n; ++ i) lst.Add(i);
  29.             foreach (int i in lst) Console.WriteLine(i);
  30.             Console.WriteLine();
  31.             Div(ref lst, 2);
  32.             foreach (int i in lst) Console.WriteLine(i);
  33.         }
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement