Does C# require .NET
I'm new to C# (but not to programming) and I was wondering: do C# programs a开发者_JAVA百科lways require .NET, or are there ways to avoid dependencies and make the application independent?
Yes C# always requires the .NET runtime.
If you are worried about other platforms there is Mono which will allow .NET applications to run on platforms other than Windows (i.e. Linux) using the Mono runtime.
C# code is compiled into CIL code which is a platform-independent instruction set, I quote from Wikipedia:
During compilation of .NET programming languages, the source code is translated into CIL code rather than platform or processor-specific object code. CIL is a CPU- and platform-independent instruction set that can be executed in any environment supporting the Common Language Infrastructure, such as the .NET runtime on Windows, or the cross-platform Mono runtime.
A CLI runtime/interpreter is required, but it doesn't have to be .NET.
Currently there is one other CLI interpreter, MONO, for Linux.
C# isn't compiled to native code, and therefore the computer can't read it. You need the .Net framework to convert the so called bytecode (the code that the C# compiler compiles to, CLI) can be converted by the Just In Time compiler of the .Net framework.
Mono is an alternative framework, and it can also run C#. It is supported on more platforms then then the .Net framework (that only supports Windows).
So yes, either the .Net framework or the Mono runtime is needed to run C# applications, new versions of Windows automatically install and update the .Net framework.
Apparently .NET runtime is not required, see MonoTouch for example.
It is possible. C# is just a programming language, and just like any other programming: It can be compiled in any way you can think of: That includes compiling without .NET. In fact, the MONO project (C# for a lot of platforms) does just that.
There are some other commercial compilers available that will pretend to compile your application without .NET , but they just stick .NET in your executable: which is useless, slow and just stupid.
Any other way to use C# without .NET or MONO would be more of an educational experience than a practical solution. As for what the education experience is worth: If you have the time, I would definitely recommend trying something like it when you have a bit more experience.
Just as C programs typically require a C runtime, C# programs require the common language runtime.
精彩评论