正如标题所暗示的那样,我试图将流阅读器获取的文件发送到另一个类,以便该类可以从中提取信息。我曾尝试在表单中提取它,但这让人感到困惑,而且我确定这是一种糟糕的做法。任何人都可以提出一种方法吗?
这是标识文件的类..
namespace DistanceEstimatorFinal
{
public partial class Form1 : Form
private void openDataListToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "CSV files (*.csv)|*.csv|Text files ( *.txt)|*.txt |All files (*.*)|*.*";
if (ofd.ShowDialog(this).Equals(DialogResult.OK))
{
Stream fileStream = ofd.OpenFile();
using (StreamReader reader = new StreamReader(fileStream))
{
}
}
}
现在我需要某种方式将它发送到这里......我看不出如何:[
namespace DistanceEstimatorFinal
{
public class dataPoints
{
List<dataPoint> Points;
public dataPoints( )
{
Points = new List<dataPoint>();
TextReader tr = new StreamReader();
string input;
while ((input = tr.ReadLine()) != null)
{
string[] bits = input.Split(',');
dataPoint a = new dataPoint(bits[0],bits[1],bits[2]);
Points.Add(a);
}
tr.Close();
}
internal dataPoint getItem(int p)
{
if (p < Points.Count)
{
return Points[p];
}
else
return null;
}
}
}
任何帮助将不胜感激