I need to read in data from a text file, through steamreader, then move that information into another class (I named it info), finally move that into a textbox. I am not sure that I am doing this right at all, am new to it.
The error I get is “work2.info does not contain a constructor that takes 2 arguments”
So here’s the code I have to read data in
private void openToolStripMenuItem1_Click(object sender, EventArgs e)
{
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "text files (*.txt)|*txt";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
StreamReader data = new StreamReader(myStream);
string newinfo = data.ReadLine();
string oldinfo = data.ReadLine();
info pepinfo = new info(newinfo, oldinfo);
pepinfo.newinfo = textBox1.Text;
pepinfo.oldinfo = textBox2.Text;
The class I want to put the data in is
public class info
{
public string newinfo
{
}
public string oldinfo
{
}
}
There is no constructor that takes 2 arguments in the code that you provided.
Your class could look like this: