Click to See Complete Forum and Search --> : Running a C# program
neil9999
12-10-2003, 12:33 PM
Hi,
I've just started C# (I've seen in several places that C++ is outdated) and have found this code:
/*
HelloWorld.cs - First C# Program
Written by - Saurabh Nandu
Compilation:
csc HelloWorld.cs
*/
namespace MasterCSharp.Samples
{
public class HelloWorld
{
public static void Main()
{
//Print Hello World
System.Console.WriteLine( "Hello World !" );
}
}
}
I've saved it as helloworld.cs . How do i run the program?
I've installed Microsoft .NET Framework SDK v1.1.
Thanks,
Neil
TheBearMay
12-10-2003, 12:49 PM
Haven't worked with C#, but my guess is that you need to compile the code and that it will generate an EXE that can be executed.
neil9999
12-10-2003, 12:52 PM
Thanks for replying,
How do I compile the code?
Neil
TheBearMay
12-10-2003, 01:02 PM
From what I'm told you'll need to get out to the command prompt. Then run sdkvars.bat to set up the environment, and then the compiler command is:
CSC helloworld.cs
TheBearMay
12-10-2003, 01:04 PM
Might also want to bookmark this site:
http://msdn.microsoft.com/
neil9999
12-10-2003, 01:13 PM
so say the path of my file is c:/helloworld.cs, how do I do it, step by step in command prompt?
Thanks again for your help,
Neil
AdamBrill
12-10-2003, 01:53 PM
I just thought I would point out that the places that you found that said that C++ was "outdated" were incorrect. While C++ is harder to use, if you code it properly, it will be faster than C#. Many people don't care much about speed now, since computers are fast enough anyway, but if you are planning on making a game(or some other high-processing application), C/C++ is by far better; but if you are just making simple applications, C# is probably better since it is fast enough and much easier to use.
BTW, the reason to this post is I couldn't stand hearing anyone say that C++ is outdated. :D :D
TheBearMay
12-10-2003, 02:20 PM
Should be something like:
path-of-sdk\sdkvars.bat
csc c:\helloworld.cs
helloworld
neil9999
12-12-2003, 01:10 PM
Sorry, I can't get this to work. I have Win XP. If I go into Command Prompt and type help, it doesn't list csc as a command. Any suggestions?
Thanks for your help,
Neil
TheBearMay
12-12-2003, 01:18 PM
CSC isn't a Windows command or an old DOS command so Help won't know about it. What's the path of the SDK? There's usually a Bin directory or similar under it that will have a few Bat files (sdkvars.bat, etc.) and some Exe and Dll files. That's where the CSC executable should be - you may have to CD over to it under the command prompt to get started.
neil9999
12-13-2003, 03:30 AM
The path is C:\Program Files\Microsoft.NET\SDK\v1.1\Bin\sdkvars.bat. So there's some file I need to run to get the CSC command recognized? Which file is this?
Thanks,
Neil
PeOfEo
12-13-2003, 11:59 AM
the main use of C# is for asp.net, why would you use it to script in for programs? I have heard that ms will be dropping c# in a few years from an ms employee. That might not be true but you never know, he would know better then we would.