【发布时间】:2017-01-26 05:42:46
【问题描述】:
我有一个具有以下结构的集合。
List<QuestionAnswer> answers = new List<QuestionAnswer>(){};
class QuestionAnswer
{
string Question { get; set; }
string Answer { get; set; }
}
它填充了以下数据:
Question Answer
Q1 a
Q1 b
Q2 c
Q2 d
Q2 e
我需要将其转换为以下格式:
Q1 Q2
a c
a d
a e
b c
b d
b e
问题直到运行时才知道;集合中可能有 n 个问题。我相信我需要自行交叉加入集合,并以某种方式将问题显示为标题(枢轴行和列)。我无法生成目标数据格式。任何帮助表示赞赏。
【问题讨论】:
标签: c# linq pivot cartesian-product