mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
Fix potential issue
This commit is contained in:
1 parent
5941f31c2b
commit
36bca4bbbb
1 file changed
+4
@@ -126,6 +126,8 @@ namespace EHR
|
||||
public static IEnumerable<IEnumerable<T>> Partition<T>(this IEnumerable<T> collection, int parts)
|
||||
{
|
||||
var list = collection.ToList();
|
||||
if (parts <= 0 || list.Count == 0) yield break;
|
||||
if (parts > list.Count) parts = list.Count;
|
||||
int size = list.Count / parts;
|
||||
int remainder = list.Count % parts;
|
||||
int index = 0;
|
||||
@@ -146,6 +148,8 @@ namespace EHR
|
||||
/// <returns>An array of arrays, each containing a part of the original array</returns>
|
||||
public static IEnumerable<IEnumerable<T>> Partition<T>(this T[] collection, int parts)
|
||||
{
|
||||
if (parts <= 0 || collection.Length == 0) yield break;
|
||||
if (parts > collection.Length) parts = collection.Length;
|
||||
int size = collection.Length / parts;
|
||||
int remainder = collection.Length % parts;
|
||||
int index = 0;
|
||||
|
||||
Reference in new issue
Block a user