コード例 #1
0
ファイル: RadExtensions.cs プロジェクト: Radolyn/RadLibrary
        /// <summary>
        ///     Returns random item from enumerable
        /// </summary>
        /// <param name="enumerable">The enumerable</param>
        /// <typeparam name="T">The type</typeparam>
        /// <returns>Random item</returns>
        public static T RandomItem <T>([NotNull] this IEnumerable <T> enumerable)
        {
            var collection = enumerable is ICollection <T> coll ? coll : enumerable.ToList();

            return(collection.Count == 0
                ? default
                : collection.ElementAt(RadUtilities.RandomInt(0, collection.Count)));
        }
コード例 #2
0
 internal static void Initialize()
 {
     try
     {
         RadUtilities.Initialize(false);
     }
     catch
     {
         Console.WriteLine("Failed to initialize RadLibrary");
     }
 }