示例#1
0
        public static T GetRandomWhile <T>(
            this IEnumerable <T> set,
            out bool isFound,
            Func <T, bool> predicate
            )
        {
            var list = new System.Collections.Generic.List <T>(set);

            while (list.IsNotEmpty())
            {
                var item = list.GetRandom();
                if (predicate(item))
                {
                    isFound = true;
                    return(item);
                }

                list.Remove(item);
            }

            isFound = false;
            return(default(T));
        }