c# newbie Q. converting string to int

MMB

New member
Joined
Jul 30, 2003
Messages
1
hi guys
now iam studying c# from c# how to program by deitel
and when i came to build my simple proggie
i had an error
i checked my code then came to build the code that comes with the book itself
it gave me the same error

here is the code
// Fig. 3.11: Addition.cs
// An addition program.

using System;

namespace AdditionProgram
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Addition
{
static void Main( string[] args )
{
//
// TODO: Add code to start application here
//

string firstNumber, // first string entered by user
secondNumber; // second string entered by user

int number1, // first number to add
number2, // second number to add
sum; // sum of number1 and number2

// prompt for and read first number from user as string
Console.Write( "Please enter the first integer: " );
firstNumber = Console.ReadLine();

// read second number from user as string
Console.Write( "\nPlease enter the second integer: " );
secondNumber = Console.ReadLine();

// convert numbers from type string to type int
number1 = Int32.Parse( firstNumber );
number2 = Int32.Parse( secondNumber );

// add numbers
sum = number1 , number2;

// display results
Console.WriteLine( "\nThe sum is {0}.", sum );

} // end method Main

} // end class Addition

} // end namespace AdditionProgram



and this is the error i get


C:\Documents and Settings\linux win!\My Documents\Visual Studio Projects\ConsoleApplication1\Class1.cs(23): The type or namespace name console could not be found (are you missing a using directive or an assembly reference?)


C:\Documents and Settings\linux win!\My Documents\Visual Studio Projects\ConsoleApplication1\Class1.cs(26): The type or namespace name int32 could not be found (are you missing a using directive or an assembly reference?)
 
I have copy your code in a new appl in VS and it works....

only one error was in it when you add numbers you must use "+"
like:

sum = number1 + number2;

Have you created a ConsoleApplication??

try to make a new Project
 
Back
Top