如果我循环浏览列表中的项目,我如何获得每个项目的位置(如果有5个项目,则为1,2,3,4和5?
public void AllocatePosition(List<DbConnect.BidList> createBidList)
{
for (int i = 0; i < createBidList.Count; i++)
{
MessageBox.Show(createBidList[i].ToString()); // show position of item (i.e. is it first, second, third...on the list
}
}
答案 0 :(得分:1)
public void AllocatePosition(List<DbConnect.BidList> createBidList)
{
for (int i = 0; i < createBidList.Count; i++)
{
MessageBox.Show("Position: " + i + " Item: " + createBidList[i].ToString());
}
}
i
变量包含位置。通常i
用于for循环,传统上它代表“index”。
答案 1 :(得分:0)
看看
for (int i = 0; i < createBidList.Count; i++)
i
是列表中项目的位置,除非我遗漏了某些内容。所以你想要
for (int i = 0; i < createBidList.Count; i++)
{
MessageBox.Show(i.ToString()); // show position of item (i.e. is it first, second, third...on the list
}