네임 스페이스 은행 {
공용 클래스 거래 { 공용 클래스 날짜 { 공공 INT의 년, 월, 일, } 공개 날짜 date = 새 날짜(); 공개 double 금액; public long acc_no; public string action; }
class Program
{
static void Main(string[] args)
{
List<Transaction> transaction = new List<Transaction>();
StreamReader sr = new StreamReader("transaction.csv");
string data = sr.ReadLine();
while (data != null)
{
string[] dataarray = data.Split(',');
string[] date_split = dataarray[0].Split('-');
Transaction tran_obj = new Transaction();
tran_obj.date.day = int.Parse(date_split[0]);
tran_obj.date.month = int.Parse(date_split[1]);
tran_obj.date.year = int.Parse(date_split[2]);
tran_obj.acc_no = long.Parse(dataarray[1]);
tran_obj.amount = double.Parse(dataarray[2]);
tran_obj.action = dataarray[3];
transaction.Add(tran_obj);
data = sr.ReadLine();
}
Console.WriteLine("Please enter the account number for which you are looking for");
long new_acc_no = long.Parse(Console.ReadLine());
foreach (Transaction t in transaction)
{
if (t.acc_no == new_acc_no)
{
Console.WriteLine(t.amount);
Console.WriteLine(t.date);
Console.WriteLine(t.action);
}
}
string s = Console.ReadLine();
}
string s = Console.ReadLine();
}
}
코드의 문제는 출력 콘솔에 난 가입일이 1994년 12월 2일
같은 날짜를 저장 한 날짜 를 도시하지 않은 것입니까? 예, 할 수 있습니다. 중첩 클래스는 좋은 아이디어가있는 경우에만 수행해야합니다. 대부분의 경우이 작업을 원하지 않습니다. – BradleyDotNET