纳金网

标题: C#经常遇到得数组随机排序 [打印本页]

作者: 狂风大尉    时间: 2015-2-28 23:11
标题: C#经常遇到得数组随机排序

using unityEngine;
using System.Collections;
using System.Collections.Generic;

public class list : MonoBehaviour {
    List<string> ListName = new List<string>();

    void Start () {
        ListName.Add ("a1");
        ListName.Add ("b2");
        ListName.Add ("c3");
        ListName.Add ("d4");
        ListName.Add ("e5");
        ListName.Add ("f6");

        ListName = RandName (ListName);
        foreach (string name in ListName) {
            print(name);        
        }

    }
//suijishuzu
    List<string>RandName(List<string>OldName)
    {
        List<string> NListName=new List<string>();
        while (NListName.Count<OldName.Count) {
            int i=Random.Range(0,OldName.Count);
            if(!NListName.Contains(OldName[i]))
                NListName.Add(OldName[i]);
        }
        return NListName;
    }


}




欢迎光临 纳金网 (http://www.narkii.com/club/) Powered by Discuz! X2.5