我希望在加载表单时从列表框/列表视图中的文本文件中显示前三个客户及其总金额,我想知道是否可以使用数组?文本文件中有多个数字,包括其他初始投资金额,利息金额。所以我需要它才能找到总金额和前三名客户名称。
到目前为止,我已经尝试了这个并且它不起作用,listbox或listview的工作会更好吗?我应该尝试另一种方法吗?所以我想知道你是否可以帮我这个?谢谢:))
private void Form5_Load(object sender, EventArgs e)
{
foreach (var line in File.ReadLines("transactions.txt"))
{
listView1.View = View.Details;
listView1.HeaderStyle = ColumnHeaderStyle.None;
listView1.Columns.Add(new ColumnHeader { Width = listView1.ClientSize.Width - SystemInformation.VerticalScrollBarWidth });
int[] array = new int[] {};
int[] largest = array
.OrderByDescending(item => item)
.Take(array.Length).ToArray();}
//Here is the code for the transactions.txt file and what it contains.
public void CreateFile()
{
StreamWriter outputFile;
outputFile = File.AppendText("transactions.txt");
outputFile.WriteLine("Transaction Number :" + " " + TransactionIDLabel.Text);
outputFile.WriteLine("Investor :" +" " + InvestorNameLabel.Text);
outputFile.WriteLine("Initial Amount" + " " +AmountLabel.Text);
outputFile.WriteLine("Date Invested" +" " +DateLabel.Text);
outputFile.WriteLine("Period Chosen" + " "+DaysInvestedLabel.Text);
outputFile.WriteLine("Rate Chosen" + " " + RateLabel.Text);
outputFile.WriteLine("Total Interest" + " " +InterestAmountLabel.Text);
outputFile.WriteLine("");
outputFile.Close();
}
答案 0 :(得分:0)
您的代码不完整(可能不正确)。如果你想找到第一个前三名,你应该使用
array.OrderByDescending(item => item).Take(3)
我找不到
listView1.View = View.Details; listView1.HeaderStyle =
ColumnHeaderStyle.None; listView1.Columns.Add(new ColumnHeader { Width
= listView1.ClientSize.Width - SystemInformation.VerticalScrollBarWidth });
您添加列的文本中的foreach行。 ?!?