rrqqq

using?System;

using?System.Collections.Generic;

namespace?Demo

{

class?Program

{

static?void?Main(string[]?args)

{

//初始化用户信息,这里用字母代替

List<string>?list?=?new?List<string>()

{

"AAA","BBB","CCC","DDD","EEE","FFF","GGG",

"HHH","III","JJJ","KKK","LLL","MMM","NNN",

"OOO","PPP","QQQ","RRR","SSS","TTT"

};

//用于存储中奖用户

List<string>?resultList?=?new?List<string>();

//用于随机索引

Random?random?=?new?Random((int)DateTime.Now.Ticks);

//循环取出中奖用户(这里我全部打印出来了)

while?(list.Count?!=?0?&&?list?!=?null)

{

int?index?=?random.Next(0,?list.Count);

//这段代码没有实际意义,只为了分隔每次取五条数据

if?(resultList.Count?%?6?==?0)

{

resultList.Add("---------");

}

//将中奖用户存储到结果集合中,并移除掉源用户集合中的数据

resultList.Add(list[index]);

list.Remove(list[index]);

}

foreach?(string?item?in?resultList)

{

Console.WriteLine(item);

}

Console.ReadKey();

}

}

}

运行结果:

---------

JJJ

SSS

NNN

CCC

PPP

---------

KKK

LLL

AAA

MMM

BBB

---------

RRR

QQQ

TTT

III

HHH

---------

OOO

DDD

FFF

GGG

EEE