我有陣列object[,]
與從Excel(整數,雙精度,日期)的值,我有類:轉換[,]列出在C#<Class>
class Foo1
{
public int A {get; set;}
public Bar B {get; set;}
public List<Baz> C {get; set;}
public double D {get; set;}
}
我需要將數據從數組轉換爲類字段中的值。
我有不同的Foo
類與其他數組的整數,列表等。 數組的大小[40,70]或[100,144](示例)。
一些代碼:
var data[,] = { {1.1, 2.2, 3.3, ...}, {5.5, 6.6, 7.7 ...} }
var dest = new List<Foo1>();
而且我有dest[0]
項目映射:
row | col | destination
-----------------------
0 | 0 | dest[0].A
0 | 1 | dest[0].B.SomeField
0 | 2 | dest[0].C.first_item
0 | 3 | dest[0].C.second_item
0 | 4 | dest[0].D
dest[1]
項目開始第1行中
我想結果List<Foo1>
dest[0].A = 1.1
dest[0].B.some_field = 2.2
dest[0].C[0].some_field = 3.3
dest[0].C[1].some_field = 4.4
....
dest[1].A = 5.5
dest[1].B.some_field = 6.6
如何儘可能快地做到這一點,沒有數百萬的if
,foreach
。
你的問題不是很清楚,甚至沒有表現出解決問題的努力。你可能想要改進它,然後它會關閉...... – Noctis
我不知道你在做什麼。你能否以一種不需要我們成爲領域專家的方式來解釋這一點? –
您能否更清楚地闡明問題?另外,請舉一些完整的例子,並強調一點,在哪裏卡住。一些給定的投入和所需的產出將不勝感激。 –