Skip to main content
gamedev.net
🔒 Locked

C# problem

Started by Chief_Voyager 4 replies 400+ views
Original Post
Chief_Voyager
Chief_Voyager
I got the book Teach Yourself the C# Language in 21 Days, and I just completed day 1. I did a little practice code at the end of the chapter, and I''m pretty sure that I got everthing right. But I keep getting this error "the type or namespace ''e'' could not be found (are you missing a using directive or assembly reference? CS0246) I figure that the "using" deal is it''s missing something from the top of the source, but I typed it in exactly as it was in the book. I checked the book''s website, but there was no info on this. I''ve included the code if anyone wants to have a look at it. Thanks. using System; using System.IO; /// /// Class to a number listing. Assumes fewer than 1000 lines. /// class NumberIT { /// /// The main entry point for the application /// public static void Main(string[] args) { // check to see if a file name was included on the // command line if (args.Length <= 0) { Console.WriteLine("\nYou need to include a filename."); } else { // declare objects for connecting files... StreamReader InFile = null; StreamWriter OutFile = null; try { // Open file name included on command line... InFile = File.OpenText(args[0]); // Create the output file... OutFile = File.CreateText("outfile.txt"); Console.Write("\nNumbering..."); // Read first line of the file... string line = InFile.ReadLine(); int ctr = 1; // loop through the file as long as not at the end... while (line != null) { OutFile.WriteLine("{0}: {1}", ctr.ToString().PadLeft(3, ''0''), line); Console.Write("..{0}..", ctr.ToString()); ctr++; line = InFile.ReadLine(); } } catch (System.IO.FileNotFoundException) { Console.WriteLine("Error: {0}", e.Message); } finally { if(InFile != null) { // Close the files InFile.Close(); OutFile.Close(); Console.WriteLine("...Done."); } } } } }
You''re about as ate up as a football bat.
Chief_Voyager
Chief_Voyager
nevermind, I found the problem. I left out some stuff (typing while tired is not good!)
You''re about as ate up as a football bat.
haro
haro
catch (System.IO.FileNotFoundException)
{
Console.WriteLine("Error: {0}", e.Message);
}


There is no defined class or instance ''e''.
thedevdan
thedevdan
Here is your problem:

catch (System.IO.FileNotFoundException)

should be:

catch (System.IO.FileNotFoundException e)
Not giving is not stealing.
Chief_Voyager
Chief_Voyager
Yeah, I left this out, it should have been this:

catch (System.IO.FileNotFoundException)
{
Console.WriteLine("Could not find the file {0}", args[0]);
}

catch (Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
}

Thanks for the quick replies. This was only day 1 in this book so I look forward to learning what all that stuff means. By the way, what''s the proper way to post code on this forum?

You''re about as ate up as a football bat.
haro
haro
You can use ["source"] and ["/source"] tags and enclose the code between them. Just minus the quotes.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.