すべての行を列に変換するにはどうすればよいですか?最初の列がLINQを使用して列名として生成されることを考慮してください。製品は、製品1のように、重複している場合LINQを使用して列を列に変換する方法は?
計算合計:
私は
YKey Year Product1 Product2 Product3
Y1 2016 3 2 3 4
Y2 2017 5 3 4 5
Y3 2018 7 4 5 6
Y4 2019 9 5 6 7
Y5 2020 11 6 7 8
Y6 2021 13 7 8 9
Y7 2022 15 8 9 10
Y8 2023 17 9 10 11
Y9 2024 19 10 11 12
Y10 2025 21 11 12 3
は、私はちょうど持っているリストとして出力の下に取得する必要があります
Product Y1 Y2 Y3 Y4 Y5 Y6 Y7 Y8 Y9 Y10
Product1 1 2 3 4 5 6 7 8 9 10
Product1 2 3 4 5 6 7 8 9 10 11
Product2 2 3 4 5 6 7 8 9 10 11
Product3 3 4 5 6 7 8 9 10 11 12
Product4 4 5 6 7 8 9 10 11 12 13
リストは、データの下に含まれてい私の要件に関する明確なイメージを提供するために、4年間の製品を提供しています。 ..
に私は見ない例としてlist<class>
private List<Data> CreateColumnData()
{
var list = new List<Data>();
list.Add(new Data() { ProductName = "Product1", Year1 = 1, Year2 = 2, Year3 = 3, Year4 = 4, Year5 = 5, Year6 = 6, Year7 = 7,Year8 = 8,Year9=9,Year10=10});
list.Add(new Data() { ProductName = "Product2", Year1 = 2, Year2 = 3, Year3 = 4, Year4 = 5, Year5 = 6, Year6 = 7, Year7 = 8, Year8 = 9, Year9 = 10, Year10 = 11 });
list.Add(new Data() { ProductName = "Product3", Year1 = 3, Year2 = 4, Year3 = 5, Year4 = 6, Year5 = 7, Year6 = 8, Year7 = 9, Year8 = 10, Year9 = 11, Year10 = 12 });
list.Add(new Data() { ProductName = "Product4", Year1 = 4, Year2 = 5, Year3 = 6, Year4 = 7, Year5 = 8, Year6 = 9, Year7 = 10, Year8 = 11, Year9 = 12, Year10 = 13});
return list;
}
public class Data
{
public string ProductName { get; set; }
public int Year1 { get; set; }
public int Year2 { get; set; }
public int Year3 { get; set; }
public int Year4 { get; set; }
public int Year5 { get; set; }
public int Year6 { get; set; }
public int Year7 { get; set; }
public int Year8 { get; set; }
public int Year9 { get; set; }
public int Year10 { get; set; }
public int Year11 { get; set; }
public int Year12 { get; set; }
public int Year13 { get; set; }
public int Year14 { get; set; }
public int Year15 { get; set; }
}
** input **クラス( 'Data')定義とサンプルデータを提供してもらえますが、** output **クラスはどうですか? –