Code sample in MS ebook gives lots of errors |
|
Author |
Message |
zenzai
|
Posted: Visual C# Express Edition, Code sample in MS ebook gives lots of errors |
Top |
I've just installed VC# Express, and created a Console Application, using the code sample from page 49-50 in the "Build a program now!" ebook from MS.
Everything looks like it should in the code window (I copy/pasted the code), nevertheless I get 21 errors when I press F5.
Most of them look like this one:
"Error 16 Invalid token '(' in class, struct, or interface member declaration"
Here's the code, copied from the code window:
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 namespace MyFirstConsoleApplication
6 {
7 class Program
8 {
9 static void Main(string[] args)
10 {
11 // Declaring two integer numbers variables that will hold the 2 parts
12 // of the sum and one integer variable to hold the sum
13 int number1;
14 int number2;
15 int sum;
16
17 // Assigning two values to the integer variables
18 number1 = 10;
19 number2 = 5;
20
21 // Adding the two integers and storing the result in the sum variable
22 sum = (number1 + number2);
23
24 // Displaying a string with the 2 numbers and the result.
25 Console.WriteLine( "The sum of " + number1.ToString() + " and " + number2.
ToString() + " is " + sum.ToString());
26 }
27 }
28
Any idea what's wrong here
Rich
Visual Studio Express Editions10
|
|
|
|
|
ahmedilyas
|
Posted: Visual C# Express Edition, Code sample in MS ebook gives lots of errors |
Top |
to me looks like you are missing one closing brace } - try placing it on the last line
|
|
|
|
|
zenzai
|
Posted: Visual C# Express Edition, Code sample in MS ebook gives lots of errors |
Top |
| to me looks like you are missing one closing brace } - try placing it on the last line |
|
Thanks - actually you're right, but it does not help to add the brace, unfortunately
Here's all the errors:
Error 1 A namespace does not directly contain members such as fields or methods 1 1 Error 2 { expected 5 38 Error 3 A namespace does not directly contain members such as fields or methods 6 1 Error 4 { expected 7 16 Error 5 Invalid token '8' in class, struct, or interface member declaration 8 1 Error 6 ; expected 9 34 Error 7 Invalid token '10' in class, struct, or interface member declaration 10 1 Error 8 Invalid token '14' in class, struct, or interface member declaration 14 1 Error 9 Invalid token '15' in class, struct, or interface member declaration 15 1 Error 10 Invalid token '16' in class, struct, or interface member declaration 16 1 Error 11 Invalid token '=' in class, struct, or interface member declaration 18 12 Error 12 Invalid token '=' in class, struct, or interface member declaration 19 12 Error 13 Invalid token '=' in class, struct, or interface member declaration 22 8 Error 14 Invalid token '+' in class, struct, or interface member declaration 22 19 Error 15 Invalid token ')' in class, struct, or interface member declaration 22 28 Error 16 Invalid token '(' in class, struct, or interface member declaration 25 21 Error 17 Invalid token '(' in class, struct, or interface member declaration 25 54 Error 18 Invalid token '(' in class, struct, or interface member declaration 26 9 Error 19 Invalid token '(' in class, struct, or interface member declaration 26 35 Error 20 A namespace does not directly contain members such as fields or methods 28 1 Error 21 A namespace does not directly contain members such as fields or methods 29 1 Error 22 Type or namespace definition, or end-of-file expected 29 4
|
|
|
|
|
nobugz
|
Posted: Visual C# Express Edition, Code sample in MS ebook gives lots of errors |
Top |
I got 21 compiler errors too. Don't type in the line numbers. Thanks, you made my day.
|
|
|
|
|
ahmedilyas
|
Posted: Visual C# Express Edition, Code sample in MS ebook gives lots of errors |
Top |
LOL no bugz
I thought the user switched on the line numbering system in the IDE then copied and pasted it....well, from the original post anyway
|
|
|
|
|
zenzai
|
Posted: Visual C# Express Edition, Code sample in MS ebook gives lots of errors |
Top |
| I got 21 compiler errors too. Don't type in the line numbers. Thanks, you made my day.
|
|
Ahh... thanks! I'm used to Liberty Basic Workshop, where you actually use line numbers, so I didn't see anything unusual... :)
|
|
|
|
|
zenzai
|
Posted: Visual C# Express Edition, Code sample in MS ebook gives lots of errors |
Top |
|
LOL no bugz
I thought the user switched on the line numbering system in the IDE then copied and pasted it....well, from the original post anyway
|
|
No actually the code in the book had line numbers, and I just copy/pasted it into the editor.
Rich
|
|
|
|
|
ahmedilyas
|
Posted: Visual C# Express Edition, Code sample in MS ebook gives lots of errors |
Top |
really wow. Wonder why they did that, ah well, at least you got the problem sorted and now you are on your way to development on the .NET platform :-D
|
|
|
|
|
zenzai
|
Posted: Visual C# Express Edition, Code sample in MS ebook gives lots of errors |
Top |
| really wow. Wonder why they did that, ah well, at least you got the problem sorted and now you are on your way to development on the .NET platform :-D |
|
Yes, it's very exciting. VC# is cool :)
|
|
|
|
|
|
|