我有一个列表 Dars
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PantaRei.Components
{
public class Dars
{
public float OpBal { get; set; }
public float PlNeOrRec { get; set; }
public float MiCaCol { get; set; }
public float MiDeCol { get; set; }
public float MiWrOff { get; set; }
public float ClBal { get; set; }
public float Tot
{
get { return OpBal+ PlNeOrRec+ MiCaCol + MiDeCol + MiWrOff; }
}
}
}
我创建了一个新的 dars
Dars secA1 = new Dars();
然后我用这段代码来填充它
public static void GetData(ref Dars secA1, Ddr ddr, Ddrs ddrs, Type pTypes)
{
Array typesEnum = Enum.GetValues(pTypes);
foreach (Enum types in typesEnum)
{
string pType = StringEnum.GetStringValue(types);
secA1.OpBal = ddrs.Out.Sum(o => o.Amount);
secA1.MiDeCol += ddr.Dil.Where(dil => dil.ProductType == pType && dil.ToBeSold).Sum(dil => dil.Amount);
secA1.PlNeOrRec += ddr.Rec.Where(rec => rec.ToBeSold).Sum(rec => rec.Amount);
GetMiCaCol(ref secA1, ddr, pType);
GetMiWrOff(ref secA1, ddr, pType);
}
}
现在我想做这样的事情
int i = 11;
foreach (float g in secA1)
{
daily.Cells[i, 4] = g;
i++;
}
但我收到了这个错误
foreach 语句不能对“PantaRei.Components.Dars”类型的变量进行操作,因为“PantaRei.Components.Dars”不包含“GetEnumerator”的公共定义
我该如何解决这个问题?