如何從“過期天數”和“正常”列中洗掉 0?
我感謝任何和所有評論
我的結果是
Book ID Borrower ID Date Borrowed Date Returned Days Loan Days Overdue Fine
0123 S10011122A 02/02/2020 06/02/2020 4 0 $0
3322 S10011126B 12/02/2020 13/02/2020 1 0 $0
1234 S10097878C 11/02/2020 01/03/2020 19 5 $2.5
8123 S10011122A 02/02/2020 06/03/2020 33 19 $9.5
3992 S10011126B 06/02/2020 09/02/2020 3 0 $0
1434 S10097878C 11/02/2020 01/03/2020 19 5 $2.5
在我的代碼(如下所示)中,我打算只顯示過期(即超過 14 天)的那些,這意味著您看到的 0 應該是空白的。這可能嗎?如果沒有,那么感謝您查看我的帖子:)
using System;
using System.IO;
namespace S10221788_Q2
{
class Program
{
static void Main(string[] args)
{
string[] csvLines = File.ReadAllLines("loaninfo.csv");
string[] heading = csvLines[0].Split(',');
Console.WriteLine("{0,-15} {1,-15} {2,-15} {3,-15} {4,-15} {5,-15} {6,-15}", heading[0], heading[1],
heading[2], heading[3], "Days Loan", "Days Overdue", "Fine");
for (int i=1; i<csvLines.Length; i )
{
string[] id = csvLines[i].Split(',');
DateTime borrowdate = Convert.ToDateTime(id[2]);
DateTime returndate = Convert.ToDateTime(id[3]);
int loan = returndate.Subtract(borrowdate).Days;
int overdue = loan - 14;
if (overdue < 0)
{
overdue = 0;
}
string fine = Convert.ToString((double)(overdue * 0.5));
Console.WriteLine("{0,-15} {1,-15} {2,-15} {3,-15} {4,-15} {5,-15} ${6,-15}",
id[0], id[1], borrowdate.ToString("dd/MM/yyyy"), returndate.ToString("dd/MM/yyyy"), loan, overdue, fine);
}
}
}
}
uj5u.com熱心網友回復:
簡單,換你行
Console.WriteLine("{0,-15} {1,-15} {2,-15} {3,-15} {4,-15} {5,-15} ${6,-15}",
id[0], id[1], borrowdate.ToString("dd/MM/yyyy"), returndate.ToString("dd/MM/yyyy"), loan, overdue, fine);
到
Console.WriteLine("{0,-15} {1,-15} {2,-15} {3,-15} {4,-15} {5,-15} ${6,-15}",
id[0], id[1], borrowdate.ToString("dd/MM/yyyy"), returndate.ToString("dd/MM/yyyy"), loan,
overdue == 0 ? "" : overdue.ToString(),
overdue == 0 ? "" : fine);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/331427.html
標籤:C#
下一篇:分發我的硬幣收藏超過28張專輯
