Newbie question - cannot get Console.WriteLine to work

  • Thread starter Thread starter barq
  • Start date Start date
B

barq

HI All,

I'm just starting on C# - I've .NET version v 2.0.507207 on my
machine.

I run a .cs having the following code from command line :

__________________________________
using System;

namespace FirstCSharpProgram

{

class FirstCSharpClass

{

static void Main()

{

Console.WriteLine ("Hello");

}

}

}

______________________________

I do not get any error , I do not get the "Hello" message either.

I just get some info about the C# compiler and the copyright stuff but
not the program's output.

Am I doing something wrong?


Thanks in advance

B
 
I just get some info about the C# compiler and the copyright stuff but
not the program's output.

Am I doing something wrong?

The compiler will not execute the program for you. Do it yourself by
running the executable file it produces (FirstCSharpClass.exe or
whatever it might be called).


Mattias
 
Once you get the other stuff figured out, add this line before the closing
brace of "Main":

Console.ReadLine();

This will keep your Console Window open so you can see the output until you
hit the ENTER key.
Peter
 
barq said:
I'm just starting on C# - I've .NET version v 2.0.507207 on my
machine.

I run a .cs having the following code from command line :

You can't *run* a .cs file. You *compile* a .cs file, and then you run
the resulting executable.
I just get some info about the C# compiler and the copyright stuff but
not the program's output.

Am I doing something wrong?

Sounds like you're compiling but not running.
 
Peter Bromberg said:
Once you get the other stuff figured out, add this line before the closing
brace of "Main":

Console.ReadLine();

This will keep your Console Window open so you can see the output until you
hit the ENTER key.

No need for that when running on the command line :)
 
LOL to original poster. Ignore my answer, i didnt read your post thoroughly.
Thought you were running a windows application inside vis studio.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top