[RESOLVED] Help with increasing int!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Help with increasing int!

Hybrid View

  1. #1
    Join Date
    Jan 2011
    Posts
    2

    [RESOLVED] Help with increasing int!

    case "north":
    Console.WriteLine("Moved North");
    int xCord;
    xCord++;
    int yCord = new int();
    yCord = 0;
    Console.WriteLine("(" + xCord + "," + yCord + ")");
    break;

    --

    Hey, I'm new to C-sharp and am having trouble with int's.

    I want to increase the xCord by value of 1, every time 'north' is entered and the loop run again.
    But with this current code, it stays at 1 no matter how many times the loop runs.

    Thanks in advance
    Attached Files Attached Files

  2. #2
    Join Date
    Oct 2005
    Location
    Seattle, WA U.S.A.
    Posts
    353

    Re: Help with increasing int!

    Have you tried moving the "int xcoord" statement outside the case statement ? (same with ycoord).

  3. #3
    Join Date
    Jun 2008
    Posts
    2,477

    Re: [RESOLVED] Help with increasing int!

    Please go and study variable lifetime/scope in C#.

  4. #4
    Join Date
    Jan 2011
    Posts
    2

    Talking Re: [RESOLVED] Help with increasing int!

    Quote Originally Posted by ThermoSight View Post
    Have you tried moving the "int xcoord" statement outside the case statement ? (same with ycoord).
    Quote Originally Posted by BigEd781 View Post
    Please go and study variable lifetime/scope in C#.
    @ThermoSight, thankyou so much! Hours of frustration over.

    @BigEd781, I've read that article now and I understand what I was doing wrong, thanks a bunch.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center