C# Basic program not compiling wtf? menu

User Tag List

Results 1 to 8 of 8
  1. #1
    ~OddBall~'s Avatar Contributor
    Reputation
    207
    Join Date
    Jan 2008
    Posts
    1,156
    Thanks G/R
    4/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    C# Basic program not compiling wtf?

    I have endeavoured to start learning C# for real this time, I am thoroughly reading and going through Wrox.Professonal.C.Sharp.2008 and so far have learnt a lot, mainly about .NET after just reading the first chapter.

    Currently on chapter #2 and have just learnt about variables (nothing new there) and am now onto scopes. I 100% understand what it's trying to tell me, however I have promised myself I will do all the code examples, actually type them out so I learn from typing it.

    This current example is showing how you can have two variables with the same name (in this case "j") as long as they aren't declared in the same method (Or something like that). Anyways here is the code below:

    Code:
    using System;
    
    namespace Wrox.ProCSharp.Basics
    {
    	class ScopeTest
    	{
    		static int j = 20;
    		Console.WriteLine(j); //Line 8!!!
    		
    		public static void Main()
    		{
    			int j = 30;
    			Console.WriteLine(j);
    			Console.WriteLine(ScopeTest.j);
    			Console.ReadLine();
    			return;
    		}
    	}
    }
    Now I've copied that completely from the book, checked it line for line and it's correct but the code does not compile.
    Error(8,20): error CS1519: Invalid Token '(' in class, struct, or interface member declaration

    Error(8,22): error CS1519: Invalid Token ')' in class, struct, or interface member declaration
    Line 8 has been bolded, I've looked at it and really cannot see what I'm doing wrong, ideas anyone?
    https://www.mmowned.com/forums/world-of-warcraft/guides/278302-selecting-bot-you.html - SELECTING THE BOT FOR YOU

    PHWOOOOAAAAAR - Parog was here. <3 <----Wtf's a Parog?

    C# Basic program not compiling wtf?
  2. #2
    Mr.Zunz's Avatar Contributor
    Reputation
    92
    Join Date
    Mar 2007
    Posts
    393
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Place line 8 in the inside of a method / function

    You can define variables outside methods / function, the rest you need to do inside a method / function,

    So basicly you can remove line 8 because you already have to same line inside the
    public static void Main()
    Last edited by WinRawr; 04-14-2010 at 06:16 AM.


  3. #3
    ~OddBall~'s Avatar Contributor
    Reputation
    207
    Join Date
    Jan 2008
    Posts
    1,156
    Thanks G/R
    4/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting, must be a mistake in the book. Thank you xD
    https://www.mmowned.com/forums/world-of-warcraft/guides/278302-selecting-bot-you.html - SELECTING THE BOT FOR YOU

    PHWOOOOAAAAAR - Parog was here. <3 <----Wtf's a Parog?

  4. #4
    maclone's Avatar / Authenticator enabled
    Reputation
    2420
    Join Date
    Nov 2007
    Posts
    8,726
    Thanks G/R
    0/1029
    Trade Feedback
    0 (0%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What for a stupid book is that then
    it's wrox, yea? you are really sure that you didn't make that mistake?
    Last edited by maclone; 04-14-2010 at 07:55 AM.
    Zomfg. And no, don't ask. - Dombo did it.

  5. #5
    Danne206's Avatar Contributor
    Reputation
    183
    Join Date
    Jan 2008
    Posts
    717
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not a mistake. The point is that you are able to use the same name on variables without them touching each other.
    Dahnniel [DOT] s [AT] gmail [DOT] com

  6. #6
    ~OddBall~'s Avatar Contributor
    Reputation
    207
    Join Date
    Jan 2008
    Posts
    1,156
    Thanks G/R
    4/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by maclone View Post
    What for a stupid book is that then
    it's wrox, yea? you are really sure that you didn't make that mistake?
    100%, but there's over 1000 pages, I'll forgive them for making one mistake.

    and ye Danne it is a mistake, because you can't execute that line outside a method. Don't know why I didn't realise that but then again I haven't done this shit in like two years.
    https://www.mmowned.com/forums/world-of-warcraft/guides/278302-selecting-bot-you.html - SELECTING THE BOT FOR YOU

    PHWOOOOAAAAAR - Parog was here. <3 <----Wtf's a Parog?

  7. #7
    Danne206's Avatar Contributor
    Reputation
    183
    Join Date
    Jan 2008
    Posts
    717
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by ~OddBall~ View Post
    100%, but there's over 1000 pages, I'll forgive them for making one mistake.

    and ye Danne it is a mistake, because you can't execute that line outside a method. Don't know why I didn't realise that but then again I haven't done this shit in like two years.
    Nope, you wont execute it. The point is still that you can use the same name on two variables, and that they're independent of each other.
    Dahnniel [DOT] s [AT] gmail [DOT] com

  8. #8
    ~OddBall~'s Avatar Contributor
    Reputation
    207
    Join Date
    Jan 2008
    Posts
    1,156
    Thanks G/R
    4/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But it doesn't compile, hence it's a mistake O_o
    https://www.mmowned.com/forums/world-of-warcraft/guides/278302-selecting-bot-you.html - SELECTING THE BOT FOR YOU

    PHWOOOOAAAAAR - Parog was here. <3 <----Wtf's a Parog?

Similar Threads

  1. C++ program wont compile
    By 2dgreengiant in forum Programming
    Replies: 8
    Last Post: 10-19-2011, 04:51 PM
  2. [Request] Basic (or not) Photoshop Editing
    By Jechob in forum Art & Graphic Design
    Replies: 7
    Last Post: 10-18-2010, 07:03 PM
  3. Visual Basic program
    By Zenathor in forum World of Warcraft Bots and Programs
    Replies: 1
    Last Post: 01-27-2010, 06:16 PM
  4. WoW bot program. NOT wow glider
    By Disphotic in forum World of Warcraft General
    Replies: 3
    Last Post: 10-17-2006, 12:39 PM
  5. Not updated? wtf..
    By myojinyahiko in forum World of Warcraft General
    Replies: 8
    Last Post: 09-13-2006, 05:02 PM
All times are GMT -5. The time now is 01:36 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search