C#获取集合中的随机个数项

using System;
using System.Collections.Generic;
using System.Linq;

static class ExtensionMethod
{

    public static IEnumerable<T> Random<T>(this IEnumerable<T> listT, int count)
    {
        return listT.OrderBy(l => Guid.NewGuid()).Take(count);
    }
}

posted @ 2022-04-12 22:45  Bridgebug  阅读(234)  评论(0编辑  收藏  举报