Testing code problem

Status
Not open for further replies.

Chaosy

Tutorial Reviewer
Level 41
Joined
Jun 9, 2011
Messages
13,289
hi, in my new school we got programming lessons and since I know basic jass the stuff they said on the first lessons I allready knew more or less. Like variables etc.

However we are supposed to learn C# and I got the "microsoft visual C# express " program to code in. However I dont get how to test my code. I just made simple test.

JASS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("afafkaf");
            Console.WriteLine("sdsa");
        }
    }
}


nothing happens when I try to test this, the cmd windows pops up for 0.1 seconds and then nothing. I get no errors from the program saying syntax error etc
 
hi, in my new school we got programming lessons and since I know basic jass the stuff they said on the first lessons I allready knew more or less. Like variables etc.

However we are supposed to learn C# and I got the "microsoft visual C# express " program to code in. However I dont get how to test my code. I just made simple test.

JASS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("afafkaf");
            Console.WriteLine("sdsa");
        }
    }
}


nothing happens when I try to test this, the cmd windows pops up for 0.1 seconds and then nothing. I get no errors from the program saying syntax error etc

Make your window either wait some time or for user response. It kind of makes sense that a program closes once it finishes doing stuff.
 
Yes except the command window is closed when the program finishes execution which happens virtually instantly. You need to either run it from a command window (which will not close after execution) or you need to keep the main thread alive (get it to sleep forever). Additionally some IDEs will log all output somewhere, even if the program finishes execution. You could also run the program in debug mode with a break point just before the main thread ends.
 
It will throw error in C# as well.

Anyway take this example
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 10; i++)
            {
                Console.Write(i + "\n"); 
            }
            Console.Write("\n"); 
            for (int i = 0, j = 9; i < 10; i++, j--)
            {
                Console.Write(i + " : " + j + "\n");
            }
            Console.Write("\n"); 
            for (int i = 0, j = 9; i < 10; )
            {
                    i++; 
                    j--;
                    Console.Write(i + " : " + j + "\n"); 
            }

            Console.Read();
        }
    }
}

For 1 ->
0
1
2
3
4
5
6
7
8
9

For 2 ->
0 9
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
9 0

For 3 ->
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
9 0
10 -1

Because in this 3rd case we first increase/reduce i/j and then write it, while in first 2 we do this after whole checking, you can use this analogy with while and do while loops.
 
Status
Not open for further replies.
Back
Top