c# List实现随机排序
来源:互联网 发布:手机指纹加密软件 编辑:程序博客网 时间:2024/05/17 05:03
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace RandomDemo{ class Program { static void Main(string[] args) { List<Student> oItem = new List<Student>(); List<Student> tItem = new List<Student>(); oItem = SetList(); Random rd = new Random(); foreach (Student item in oItem) { int index=rd.Next(tItem.Count+1); tItem.Insert(index, item); } foreach (Student item in tItem) { Console.Write(item.Name); } Console.ReadLine(); } private static List<Student> SetList() { List<Student> items = new List<Student>(); items.Add(new Student("张三1","浙江1")); items.Add(new Student("张三2", "浙江2")); items.Add(new Student("张三3", "浙江3")); items.Add(new Student("张三4", "浙江4")); items.Add(new Student("张三5", "浙江5")); items.Add(new Student("张三6", "浙江6")); return items; } }}