samedi 30 juillet 2016

I need to make groups of 4-4-3 out of this shuffledClassroom list

static void Main(string[] args) { List classroom = new List { "Armen", "Babken", "Hayk", "Edgar", "Tatev", "Anna", "Aram", "Karo", "Baghdig", "Harut", "Ruzanna" }; foreach (string student in classroom) { Console.WriteLine(student); }

        List<string> shuffledClassroom = ShuffleList(classroom);
        foreach (string student in shuffledClassroom)
        {
            Console.WriteLine(student);
        }


        Console.ReadLine();
    }

    static List<T> ShuffleList<T>(List<T> inputList)
    {
        List<T> randomList = new List<T>();

        Random rnd = new Random();
        int randomIndex = 0;
        while (inputList.Count > 0)
        {
            randomIndex = rnd.Next(0, inputList.Count); 
            randomList.Add(inputList[randomIndex]);
            inputList.RemoveAt(randomIndex);
        }
        return randomList;
    }




Aucun commentaire:

Enregistrer un commentaire