我正在使用C#适配器方法,将元素添加到列表中,然后调用该列表以填充列表框,这是我要执行的操作的按钮:
private void button1_Click(object sender, EventArgs e) {
listCustomers.Items.Clear();
List < Customer > customers = CustomerList.GetCustomers();
List < CustomerSaldo > customersSaldo = CustomerListSaldo.GetCustomers();
int total = 0;
int totalCustomer = 0;
foreach(Customer customer in customers)
total++;
listCustomers.Items.Clear();
totalCustomer = total;
int x = totalCustomer;
foreach(CustomerSaldo customer2 in customersSaldo) {
if (x >= 1) {
listCustomers.Items.Add("Costumer ID # " + x + " is: " + customer2.Saldo);
x--;
}
}
}
这是我得到的,没关系,但是我想知道是否存在一种执行此示例的方法:
客户#1余额...
客户#2余额...
客户#3余额...
如果您看到我的代码,则有一个变量x
,该变量是客户的总数,因此我认为我的排序必须以该变量开头,但是我不知道该怎么做,我该怎么办?
反转列表并开始计数,直到到达终点为止:
//Reverse the list
customersSaldo.Reverse();
//Add new items
for(int i = 0; i < customers.Count; i++)
listCustomers.Items.Add(string.Format("Costumer ID # {0} is: {1}", (i+1).ToString(), customersSaldo[i].Saldo);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句