有人可以解释为什么我得到:
“使用未分配的局部变量 number_of_column”用于: if (i < number_of_column -1)
处理这个问题的最佳方法是什么?
static void Main(string[] args)
{
int number_of_column;
if (Directory.Exists(path))
{
var file = dir.GetFiles().OrderByDescending(f => f.LastWriteTime).First();
string file1 = file.ToString();
Console.WriteLine(file1);
StreamReader sr = new StreamReader(path + "\\" + file1);
string line;
while ((line = sr.ReadLine()) != null)
{
if (start == true)
{
string[] line1 = line.Split(',');
number_of_column = line1.Count();
i = 0;
foreach (string s in line1)
{
if ((s != "0") || (!string.IsNullOrEmpty(s)))
{
col[i] = "checked";
}
i++;
}
}
else
{
if (line.Contains("Timestamp") && line.Contains("LiveStandby") && line.Contains("peak"))
{
start = true;
}
}
}
sr.Close();
i=0;
foreach (string s in col)
{
if (i < number_of_column -1)
{