c#string数组求解

qq_36659725 2017-08-22 04:45:17
string StyleCode = "";
string CodeNo = "";
int iQTY;
int i;
iQTY=0;
worksheet = workbook.Sheets[1] as Excel.Worksheet;
for (i = 6; i <= worksheet.UsedRange.Rows.Count; i++)
{
value = (worksheet.Cells[i, 1] as Excel.Range).Value2;
if (value != null)
{
if (value.ToString().Trim() != ".")
{
CodeNo = Convert.ToString((worksheet.Cells[i, 1] as Excel.Range).Value2);
StyleCode = (worksheet.Cells[i, 3] as Excel.Range).Value2 + " - " + (worksheet.Cells[i, 11] as Excel.Range).Value2;
continue;
}
else
{
iQTY = i;
}
}
}
红色字体的需要创建一个数组保存循环下来的数 求解
...全文
42 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
正怒月神 2017-08-22
声明数组存储
回复
exception92 2017-08-22
多个集合参见#1楼方式;保存到一个集合里,类似: ArrayList array = new ArrayList(); for (i = 6; i <= worksheet.UsedRange.Rows.Count; i++) { value = (worksheet.Cells[i, 1] as Excel.Range).Value2; if (value != null) { if (value.ToString().Trim() != ".") { CodeNo = Convert.ToString((worksheet.Cells[i, 1] as Excel.Range).Value2); StyleCode = (worksheet.Cells[i, 3] as Excel.Range).Value2 + " - " + (worksheet.Cells[i, 11] as Excel.Range).Value2; array.AddRange(new object[] {CodeNo ,StyleCode }); continue; } else { iQTY = i; array.Add(iQTY); } } }
回复
用两个List来存,一个是List<T>,T就是CodeNo 和StyleCode 组成的实体 还有个是List<int>,就是你的iQTY
回复
发动态
发帖子
C#
创建于2007-09-28

10.4w+

社区成员

.NET技术 C#
申请成为版主
社区公告

全世界最好的语言,没有之一.