problem with StreamReader

May 21 2007 1:08 PM
Hello! I am new to .NET. I'm trying to pick up some C#.net skills and make simple-moderate level websites. My problem is that a lot of the code samples I find on the web simply dont work on my machine. For example, here is a simple class that is supposed to read a text file ************************************************ public class Readtextfile { public static int Main(string[] args) { StreamReader re = File.OpenText("Arungg.txt"); string input = null; while ((input = re.ReadLine()) != null) { Console.WriteLine(input); } re.close; return 0; } } ************************************************ This is from a tutorial on the c-sharpcorner website --> http://www.c-sharpcorner.com/UploadFile/ggaganesh/CSAndTypes11092005011259AM/CSAndTypes.aspx I created a new asp.net website using "FileSystem" as the location and C# as the language. Then I added a new class called Readtextfile and copied the code, placing my text file in the correct directory. But I get the following errors with this 1. about re.close; only assignment, call, increment, decrement and new object expressions can be used as a statement. 2. about re.close 'System.IO.StreamReader' does not contain a definition for 'close' Ive added using System.IO; directive. I also tried putting this block of code in the aspx.cs under the Page_Load method. That didnt work either. If this problem sounds familiar to anyone, please reply back. If you dont have an answer, maybe we can figure it out together. Thanks everyone!

Answers (2)