【发布时间】:2015-07-31 06:21:39
【问题描述】:
我有多个数据类型的元组dataframe
public static void Main(string[] args) {
int[] a = { 1, 0, 3, 4, 0};
int[] b = { 3, 0, 9, 10, 0};
int[] c = { 2, 3, 3, 5, 0};
var ret = new Dictionary<string, int[]>();
ret.Add("Jack", a);
ret.Add("Jane", b);
ret.Add("James", c);
var dataframe = new Tuple<string[], Dictionary<string, int[]>, string[]>(
new string[] { "Game 1", "Game 2", "Game 3", "Game 4", "Game 5" },
ret,
new string[] { "A", "B", "C", "B", "A" }
);
dataframe.item1和dataframe.item3中的值是dataframe.item2中字典中列的不同标签。
我想按dataframe.item3 的字母顺序对元组中的项目进行排序,包括字典中数组的顺序。
所以dataframe.item3 将是{"A","A","B","B","C"}
dataframe.item1 将是 {"Game 1","Game 5","Game 2","Game 4","Game 3"}
dataframe.item2["Jack"] 将是 {1, 0, 0, 4, 3}
这是我尝试过的
//Sorting the dictionary
Dictionary<string, int[]> sortedDict = new Dictionary<string, int[]>();
for each (var item in dataframe.Item2)
{
Array.Sort(dataframe.Item3,dataframe.Item2[item])
}
//Sorting the strings and creating a new dataframe
var sorted_dataframe = new Tuple<string[], Dictionary<string, int[]>, string[]>(
Array.Sort(dataframe.Item3, dataframe.Item1),
sortedDict,
Array.Sort(dataframe.Item3)
);
【问题讨论】: