• 打乱集合顺序


    MyCollections.shuffle(ref list)
    using System;
    using System.Collections.Generic;
    using System.Text;
     
     
    public class MyCollections
    {
        public static void shuffle<T>(ref List<T> list)
        {
            Random rand = new Random(Guid.NewGuid().GetHashCode());
            List<T> newList = new List<T>();//儲存結果的集合
            foreach (T item in list)
            {
                newList.Insert(rand.Next(0, newList.Count), item);
            }
            newList.Remove(list[0]);//移除list[0]的值
            newList.Insert(rand.Next(0, newList.Count), list[0]);//再重新隨機插入第一筆
     
            list = newList;
     
        }
    }
    
    
    
    
    }
  • 相关阅读:
    File
    多态
    方法重载
    Math
    instanceof
    强制类型转换
    泛型
    springboot热部署
    iOS bug处理
    iOS8-xcode6中添加pch全局引用文件
  • 原文地址:https://www.cnblogs.com/AllNighter/p/14312300.html
Copyright © 2020-2023  润新知