I'm trying to read the contents of a text file, in this case a list of computer names (Computer1, computer2 etc,) and I thought that StreamReader would be what you would use but when I do the following:
StreamReader arrComputer = new StreamReader(FileDialog.filename)();
I got this exception:
The type or namespace name 'StreamReader' could not be found (are you missing a using directive or an assembly reference?)
I'm very new to C# so I'm sure I'm making a newbie mistake.
You need to import the System.IO
namespace. Put this at the top of your .cs file:
using System.IO;
Either that, or explicitly qualify the type name:
System.IO.StreamReader arrComputer = new System.IO.StreamReader(FileDialog.filename);
You'll need:
using System.IO;
At the top of the .cs file. If you're reading text content I recommend you use a TextReader which is bizarrely a base class of StreamReader.
try:
using(TextReader reader = new StreamReader(/* your args */))
{
}
The using block just makes sure it's disposed of properly.
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