Note that there are some explanatory texts on larger screens.

plurals
  1. POinput string was not in correct format error
    text
    copied!<p>I am trying to learn the basics of C# using Sams Teach Yourself C# in 21 days.</p> <p>I have created this program by copying it line by line from the day 1 type and run section. It compiles fine but when you run it, it gives this error: "Input string was not in the correct format".</p> <p>I am running the program from the console. </p> <p>I am using the Visual Studio 2010 Express editor. </p> <p>The code I copied is: </p> <pre><code>using System; using System.IO; /// &lt;summary&gt; /// Class to number a listing. Assumes fewer than 1000 lines. /// &lt;/summary&gt; class NumberIT { /// &lt;summary&gt; /// The main entry point for the application. /// &lt;/summary&gt; public static void Main(string[] args) { // check to see if a file name was included on the command line. if (args.Length &lt;= 0) { Console.WriteLine("\nYou need to include a filename."); } else { // declare objects for connecting to 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("{1}: {2}", ctr.ToString().PadLeft(3, '1'), line); Console.Write("..{1]..", ctr.ToString()); ctr++; line = InFile.ReadLine(); } } catch (System.IO.FileNotFoundException) { Console.WriteLine("Could not find the file {0}", args[0]); } catch (Exception e) { Console.WriteLine("Error: {0}", e.Message); } finally { if (InFile != null) { // Close the files InFile.Close(); OutFile.Close(); Console.WriteLine("...Done."); } } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload