I want to restructure my data from this question: Sorting elements inside a tuple by inner elements so that I can use LINQ to sort with the OrderBy
operation. But the dictionary I have is transposed the wrong way.
public class Gamedat
{
public string[] Games { get; set; }
public string[] Gtypes { get; set; }
public Dictionary<string, int[]> Playdata { get; set; }
}
class Program
{
static void Main(string[] args)
{
Gamedat dataframe = new Gamedat();
dataframe.Games = new string[] { "Game 1", "Game 2", "Game 3", "Game 4", "Game 5" };
dataframe.Gtypes = new string[] { "A", "B", "C", "B", "A" };
dataframe.Playdata = new Dictionary<string, int[]>();
//Add dictionary items
int[] a = { 1, 0, 3, 4, 0 };
int[] b = { 3, 0, 9, 10, 0 };
int[] c = { 2, 3, 3, 5, 0 };
dataframe.Playdata.Add("Jack", a);
dataframe.Playdata.Add("Jane", b);
dataframe.Playdata.Add("James", c);
}
What is a good way to structure the data for sorting without losing the keys from the dictionary? One possibility I thought of for sorting without the dictionary is:
public class Gamedat
{
public string Games { get; set; }
public string Gtypes { get; set; }
}
class Program
{
static void Main(string[] args)
{
List<Gamedat> dataframe = new List<Gamedat> {new Gamedat { Game = "Game 1", Gtypes = "A"},
new Gamedat { Game = "Game 2", Gtypes = "B"},
new Gamedat { Game = "Game 3", Gtypes = "C"},
new Gamedat { Game = "Game 4", Gtypes = "B"},
new Gamedat { Game = "Game 5", Gtypes = "A"},
};
var result = dataframe.OrderBy(x => x.Gtypes);
}