Skip to content

Commit 22fae9b

Browse files
committed
refactor(Random): Use ICollection instead explicit type
1 parent 65f3590 commit 22fae9b

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

Assets/JCSUnity/Scripts/Util/JCS_Random.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Copyright (c) 2017 by Shen, Jen-Chieh $
88
*/
99
using System.Collections.Generic;
10+
using System.Linq;
1011
using UnityEngine;
1112

1213
namespace JCSUnity
@@ -91,23 +92,18 @@ private static float FindDecimalInclude(float num)
9192
/// <typeparam name="T"> Type of the object. </typeparam>
9293
/// <param name="inArray"> The list or array to choose from. </param>
9394
/// <returns> The chosen object from the list or array. </returns>
94-
public static T ChooseOne<T>(T[] inArray)
95+
public static T ChooseOneE<T>(params T[] args) // Ellipsis
9596
{
96-
if (inArray.Length == 0) return default(T);
97-
int index = Range(0, inArray.Length);
98-
return inArray[index];
97+
return ChooseOne(args);
9998
}
100-
public static T ChooseOne<T>(List<T> inList)
99+
public static T ChooseOne<T>(ICollection<T> inList)
101100
{
102-
if (inList.Count == 0) return default(T);
101+
if (inList.Count == 0)
102+
return default(T);
103+
103104
int index = Range(0, inList.Count);
104-
return inList[index];
105-
}
106-
public static T ChooseOneE<T>(params T[] args) // Ellipsis
107-
{
108-
if (args.Length == 0) return default(T);
109-
int index = Range(0, args.Length);
110-
return args[index];
105+
106+
return inList.ElementAt(index);
111107
}
112108

113109
/// <summary>

0 commit comments

Comments
 (0)