我有一些不尋常的我需要做的。我想知道是否有人可以想到一個簡單的方法來做出我需要的改變。我已經是一個如何洗牌多個相關的數組?
public class Report
{
public string[] Text { get; set; }
public string[] Image { get; set; }
public string[] Explanation { get; set; }
}
報告類可以有任意數量的文字,圖片和說明,並且每個數組的大小總是一致的,但也許是每個報表實例不同。
我需要做的是能夠以隨機順序對數組元素進行排序。因此,例如我可能有
Report.Text[0] = "text0";
Report.Text[1] = "text1";
Report.Text[2] = "text2";
Report.Image[0] = "img0";
Report.Image[1] = "img1";
Report.Image[2] = "img2";
Report.Explanation[0] = "exp0";
Report.Explanation[1] = "exp1";
Report.Explanation[2] = "exp2";
然後排序
Report.Text[0] = "text2";
Report.Text[1] = "text0";
Report.Text[2] = "text1";
Report.Image[0] = "img2";
Report.Image[1] = "img0";
Report.Image[2] = "img1";
Report.Explanation[0] = "exp2";
Report.Explanation[1] = "exp0";
Report.Explanation[2] = "exp1";
誰能想到一個簡單的方法來做到這一點後?我所能想到的是,我需要創建一個尺寸相同的新臨時對象,並進行某種交換。但我不知道如何 隨機。我問的原因是爲了防止過去有人有這種需求。
我聽到第一次按隨機順序排序。同樣對於報告,我寧願使用命名屬性,像StringTemplate這樣的庫非常適合報告。不要在報告對象/類 – 2011-06-13 14:31:50