In C#, why does it need so many files to run? Why can’t it just be Program.cs
and when you type the command it will compile / run? Like how in Java, all you need is Program.java
and then you type java
Program.java
? Is there a way to set this up?
Because modern languages generally recognize that the coding experience is much more friendly when there is metadata alongside your code. See: package management in C#/Rust vs. C++/C
Or package management in python 😠took me long enough to figure that one out. IMO this is a huge plus for writing C# in general: no need to worry about project organization as VS gives you a good starter project template when you start with something new.
True…but I’d love to do some metaprogramming. I get its a very specific thing but it’d be nice
The smallest project will be a program.cs and a csproj file.
This isn’t a giant problem because there is a command you can use to create a new project easy, and otherwise its easy if you are using visual studio.
I would argue that even if you had to set it up manually, its not really a big deal since it happens only once.
C# has many other benefits compared to Java.
Ok i will try this, thank you.
You can, if you call the compiler directly, do this. There is basically no practical reason to ever do this though. You can likely pare things down to just a project file and the .cs file though and use visual studio normally.
So how do I make the .exe file save to the main folder rather than bin/debug?
Like how in Java, all you need is Program.java
and then you type java Program.java
?
That doesn’t actually work (at least with JDK 8, which I tried it on). You have to first compile the file using javac
. That generates a .class
file which you can then run with java
. And you have to take care that your directory structure matches the package structure.
Is there a way to set this up?
You can just invoke csc
on C# source files, like javac
on Java source files. This produces an executable that you can run directly if you use the .Net Framework.
It’s not quite as self-contained with .Net Core, but it still compares favourably against Java.
That doesn’t actually work (at least with JDK 8, which I tried it on).
This is a thing now!
I used to write Java code a long time ago, and I was surprised with the numerous changes that have happened with that language.
With CoreRT you can directly compile into a single file and execute your program natively.
C# devs
null reference exceptions