I'm brand new to C#, but I think I have the correct "using" statements here, so I presume the problem is somewhere in my class structure or syntax? I'm getting the "The type or namespace name 'Textreader' could not be found" error. Thank you.
using System;
using System.IO;
namespace Layouts.Test_control {
public partial class Test_controlSublayout : System.Web.UI.UserControl
{
private void Page_Load(object sender, EventArgs e) {
Textreader tr = new StreamReader("date.txt");
Console.WriteLine(tr.ReadLine());
tr.Close();
}
}
}
C# is case sensitive so you probably want this instead:
TextReader tr = new StreamReader("date.txt");
Apart from that you've mentioned in your question that you would use the correct "using" statements, but obviously you're not disposing/closing the StreamReader
at all. You're also reading only one line of the file.
// The using statement also closes the StreamReader.
using(var sr = new StreamReader("date.txt"))
{
String line;
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With