我知道這個問題prob的版本被問得很頻繁,但我調查了最後幾天的論壇,並試圖實施Fisher-Yates shuffle,但我沒有設法做到這一點因爲我總是得到一個錯誤,因爲它沒有把Shuffle作爲一個函數並給出這個錯誤:Entscheidungsfragen.Shuffle(this System.Collections.Generic.IList)':擴展方法必須在非泛型靜態類中定義。c#randomize列表<action>
private static System.Random rng = new System.Random();
public static void Shuffle<T>(this IList<T> list)
{
int n = list.Count;
while (n > 1) {
n--;
int k = rng.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
private static void CreateList(string[] args)
{
var scenes =new List<Action>(szene1, szene2);
scenes.Shuffle();
foreach (Action sce in scenes)
sce();
}
我倒是很感激,如果有人可以幫助我,因爲i'm只是失去了事業,我什麼都試過,我發現。
其中包含了'Shuffle'擴展方法必須是靜態的類,它必須是可從'CreateList'訪問。 –