/    Sign up×
Community /Pin to ProfileBookmark

Running a C# program

Hi,

I’ve just started C# (I’ve seen in several places that C++ is outdated) and have found this code:

[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 !” );
}
}
}
[/CODE]

I’ve saved it as helloworld.cs . How do i run the program?

I’ve installed Microsoft .NET Framework SDK v1.1.

Thanks,

Neil

to post a comment
Full-stack Developer

11 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayDec 10.2003 — 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.
Copy linkTweet thisAlerts:
@neil9999authorDec 10.2003 — Thanks for replying,

How do I compile the code?

Neil
Copy linkTweet thisAlerts:
@TheBearMayDec 10.2003 — 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
Copy linkTweet thisAlerts:
@TheBearMayDec 10.2003 — Might also want to bookmark this site:

[URL]http://msdn.microsoft.com/[/URL]
Copy linkTweet thisAlerts:
@neil9999authorDec 10.2003 — 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
Copy linkTweet thisAlerts:
@AdamBrillDec 10.2003 — 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. ? ?
Copy linkTweet thisAlerts:
@TheBearMayDec 10.2003 — Should be something like:

[i]path-of-sdk[/i]sdkvars.bat

csc c:helloworld.cs

helloworld
Copy linkTweet thisAlerts:
@neil9999authorDec 12.2003 — 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
Copy linkTweet thisAlerts:
@TheBearMayDec 12.2003 — 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.
Copy linkTweet thisAlerts:
@neil9999authorDec 13.2003 — The path is C:Program FilesMicrosoft.NETSDKv1.1Binsdkvars.bat. So there's some file I need to run to get the CSC command recognized? Which file is this?

Thanks,

Neil
Copy linkTweet thisAlerts:
@PeOfEoDec 13.2003 — 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.
×

Success!

Help @neil9999 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...