我目前设置这个设置来显示信用卡输入和输出:
static void ViewReport(ArrayList paymentReport) //Displays the current payments in a list
{
//Activated if the user hits the v or V key
Console.WriteLine("\n{0,-5}{1,-25}{2,-15}{3,-15}{4,-15}", "Plan", "Number", "Balance", "Payment", "APR");
foreach (PaymentPlan creditCard in paymentReport)
{
Console.WriteLine("{0,-5}{1,-25}{2,-15}{3,-15}{4,-15}",
creditCard.PlanNumber,
creditCard.CardNumber,
creditCard.CreditBalance,
creditCard.MonthlyPayment,
creditCard.AnnualRate);
}
}
我必须创建一个单独的方法,需要从最低到最高排序creditCard.CreditBalance
。那么按creditCard.CreditBalance
对列表进行排序的最佳方法是哪次会在下次用户再次打开时反映ViewReport
?
答案 0 :(得分:3)
LINQ OrderBy:
foreach (PaymentPlan creditCard in paymentReport.Cast<PaymentPlan>().OrderBy(o=>o.CreditBalance))
要更改订单,请将结果永久分配给您的变量:
paymentReport = paymentReport.Cast<PaymentPlan>().OrderBy(o=>o.CreditBalance).ToArray();