이미 시간 지정 또는 시간 경과 값을 재귀 적으로 추가하려면 어떻게합니까?이전 datetime 값에 datetime 값 추가
나는이 시도했지만 그것은 나에게 오류를 제공합니다
'A local variable named 'total' cannot be declared in this scope because it would give a different meaning to 'total, which is already in used in a 'parent or current' scope to denote something else'
private void button5_Click(object sender, EventArgs e)
{
int a = 0;
string path = @"C:\Users\Public\WriteLines.txt";
using (StreamReader sr = new StreamReader(path))
{
string line;
string[] lines = new String[500];
DateTime now = DateTime.Now;
TimeSpan total = now - now;
int temp=0;
while ((line = sr.ReadLine()) != null)
{
lines[a] = line;
a++;
}
while (temp < a)
{
TimeSpan difference = Convert.ToDateTime(lines[temp+1]) - Convert.ToDateTime(lines[temp]);
TimeSpan total = total + difference; // <----ERROR HERE
Console.WriteLine(total);
Console.WriteLine(difference);
temp = temp + 2;
}
}
}
또한 내가 재귀 적으로 값을 추가 할 수 있도록 제로로 날짜 값을 설정하는 더 좋은 방법이?
는 이미 다른 변수 이름으로 대체, 같은 이름의 변수가 있기 때문에 당신은 할 수 없어