我有一個叫做_DataCollection的List<List<string>>
,其中每個嵌套列表都有相同數量的值。雖然所有字符串都是嵌套列表中的值,但它們是由字母數字字符,空字符串或貨幣值組成的字符串。例如在每個索引中對嵌套列表進行求和的值
_DataCollection[0] = {"tom", "abc", "$525.34", "$123"}
_DataCollection[1] = {"dick", "xyz", "$100", "$234"}
_DataCollection[2] = {"harry", "", "$250.01", "$40"}
_DataCollection[2] = {"bob", "", "$250.01", ""}
我需要做的就是拿出一個辦法來總結每個索引的所有值在所有嵌套列表並且將其添加到列表什麼:
newSumList[0] = "N/A" since "tom" + "dick" + "harry" + "bob" can't be aggregated.
newSumList[1] = "N/A" since "abc" + "xyz" + "" + "" can't be aggregated.
newSumList[2] = "1125.36"
newSumList[3] = "397" even though the last value of the last nested list is "".
基本上,總所有數字每個索引的嵌套列表中的值。
我能想到的唯一方法是迭代這些並保持運行總數,但我想知道是否可以使用LINQ或其他方法來完成這項工作。