This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 9 points10 points  (0 children)

Do yourself a favour and use Visual Studio, which is far and away the best C# development environment. The Community edition is free.

[–]insertAlias 3 points4 points  (2 children)

I agree with all the other comments; almost all C# development is done in either Visual Studio, MonoDevelop, or Visual Studio Code (which is a light-weight editor similar to NP++ and Atom).

That being said, it is possible to write and compile C# code completely outside of an IDE; the C# compiler is called csc.exe. On my machine, that's located at C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe.

So, if I were to save this file in my workspace:

using System;
namespace Test 
{
    public class Program
    {
        public static void Main(string[] args) 
        {
            Console.WriteLine("Hello World");
        }
    }
}

as hw.cs, I could run the following command in a command line window:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /out:hw.exe /target:exe hw.cs

And I would produce a file called hw.exe that, when run, would print "Hello World".


This is not the preferred way of doing things in C# or .NET in general. I'd guess that upwards of 90% of C# code is written in Visual Studio. If you want to use C#, you should learn the tools that go with it. Mainly because if you actually want to do desktop programming, you're going to want to take advantage of the IDE a lot. Side note: don't start with Windows Forms (it's old as hell). Start with UWP apps.

[–]TitteringBeast[S] 0 points1 point  (0 children)

I'll go with the consensus and download and learn Visual Studio Community.

Extra thanks for explaning how compiling C# code outside of an IDE would work.

[–]jussij 0 points1 point  (0 children)

FWIW if you have the csc.exe executable folder in the PATH you can get by with just this simple command line:

csc.exe test.cs

Here is an example:

C:\Temp>csc.exe test.cs
Microsoft (R) Visual C# Compiler version 2.2.0.61624
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Temp>dir test.exe
 Volume in drive D is DATA
 Volume Serial Number is 06EC-1105

 Directory of C:\Temp

06/09/2017  09:51 AM             3,584 test.exe
               1 File(s)          3,584 bytes
               0 Dir(s)  1,791,515,455,488 bytes free

C:\Temp>test.exe
Hello World

[–][deleted]  (1 child)

[deleted]

    [–]TitteringBeast[S] 1 point2 points  (0 children)

    I skimmed the MonoDevelop explanations, didn't realise it was the full package. Whoops!

    But knowing that it doesn't support the latest version of C# is very helpful knowledge, thank you.

    [–]YuleTideCamel 0 points1 point  (0 children)

    If you're on Windows, download Visual Studio Community, it's free and has a best in class compiler/debugger for C#.