我有一组需要读取的分隔文本文件,创建一个类和对象,并在其中存储成员。我是一个初学者,只是希望指出正确的方向。任何帮助将不胜感激。非常感谢你。C#将文本文件保存到对象中的最佳方式
我做了一个类与对象:
public string left;
public string right;
和我的表单代码:
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog of = new OpenFileDialog();
of.ShowDialog();
textBox1.Text = of.FileName;
}
private void button2_Click(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(textBox1.Text);
textBox2.Text = sr.ReadToEnd();
// sr.Close();
}
private void button3_Click(object sender, EventArgs e)
{
string[] split1 = textBox2.Text.Split(';');
foreach (string segment in split1)
{
//split sub-segment
string[] split2 = segment.Split(':');
//check if it's valid
if (split2.Count().Equals(2))
{
id textfile = new id();
textfile.left += // ????
id textfile1 = new id();
textfile.right += // ????
什么语言?!? –
我不清楚你到底在问什么。 – displayname
对不起c#。忘了补充说明 – user3617347