我的类名inAndOutTime包含in和out属性(字符串 数据类型)。输入和输出属性包含一组从excel单元格获取的值(字符串数据类型)。我正在尝试进行计算以减去“ out”和“ in”,并获取值,然后显示为excel。问题:如何访问对象属性值(In0,Out0,In1,Out1 .....)并进行减法。
我尝试创建“入”数组列表和“出”数组列表,将其传递给函数,然后创建“ totalbreaktime”数组列表以存储计算后的值。在计算函数中,我尝试使用循环来循环出数组列表“输入”和“输出”并使用减号运算符。 (对C#来说是全新的)
// this is my class
public class inAndOutTime
{
public string In0 { get; set; }
public string Out0 { get; set; }
public string In1 { get; set; }
public string Out1 { get; set; }
public string In2 { get; set; }
public string Out2 { get; set; }
public string In3 { get; set; }
public string Out3 { get; set; }
public string In4 { get; set; }
public string Out4 { get; set; }
public string break_time { get; set; }
}
//retrieve value from excel
for (int row = 2; row <= rw; row++)
{
for (cCnt = 6; cCnt <= 6; cCnt++)
{
var out4 = (String)(xlworkSheet.Cells[row, 16]
as Excel.Range).Value.ToString();
Time.Out4 = out4;
Console.WriteLine(Time.Out4.ToString());
xlNewSheet.Cells[row, 16].Value = Time.Out4;
Excel.Range formatRange;
formatRange = xlNewSheet.Cells[row, 16];
formatRange.NumberFormat = "hh:mm";
out_list.Add(Time.Out4);
}
}
//call function
calculation1(in_list, out_list);
//function
public static ArrayList calculation1(ArrayList i, ArrayList o)
{
ArrayList totalbreaktime = new ArrayList();
for (int num = 0; num < o.Count; num++)
{
result = i(args[num]) - o[num];
totalbreaktime.Add(result);
Console.WriteLine(result);
}
return totalbreaktime;
}