将数据从文本文件插入到列表<>在 C# WPF 中使用自己的类



我有一个文本文件,它包含如下行:

我有一个类的X, Y和I值称为"my_points">

我想逐行读取文件,并添加一个新的"my_points">

没有语法错误,但列表读取后仍然为空。我可以打印出&;separated [0]&;,"分离[1]";或"分离[2],里面有我档案里的号码。此外,该列表还包含尽可能多的"my_points"。因为我的文本文件中有几行。这是可行的。但是所有的值都是0。所以我不明白为什么这些数字不在列表中。

我代码:

Listmy_point_list_read = new List();//在…之前初始化列表

public List<my_points> FiletoList()
{
System.IO.StreamReader my_streamreader = new System.IO.StreamReader("Textfile.txt");
string my_line;
while ((my_line = my_streamreader.ReadLine()) != null)
{
try
{
string[] seperated = my_line.Split(';');
my_point_list_read.Add(new my_points(Convert.ToDouble(seperated[0]), Convert.ToDouble(seperated[1]), Convert.ToInt32(seperated[2])));

}
catch 
{
break;
}  
}
//The class I wrote for my_points looks like this:
public class my_points
{
public double X;
public double Y;
public int i;
public my_points(double X, double Y, int i)
{
this.X = 0.0;
this.Y = 0.0;
this.i = 0;
}
}

在我的类my_points中,我将所有变量设置为零。我把它改成:

public class my_points 
{
public double X;
public double Y;
public int i;
public my_points(double X, double Y, int i)
{
this.X = X;
this.Y = Y;
this.i = i;
}
}

现在可以用了