Is C# partially interpreted or really compiled?

后端 未结 13 1102
别跟我提以往
别跟我提以往 2020-12-07 11:51

There is a lot of contradicting information about this. While some say C# is compiled (as it is compiled into IL and then to native code when run), others say it\'s interpre

13条回答
  •  -上瘾入骨i
    2020-12-07 12:33

    A purely compiled language has some advantages. Speed, as a rule, and often working set size. A purely interpreted language has some advantages. Flexibility of not needing an explicit compilation stage that allows us to edit in place, and often easier portability.

    A jitted language fits in a middle ground in this case.

    That's a reason alone why we might think of a jitted language as either compiled or as interpreted depending on which position on which metric we care about attaining, and our prejudices for and against one or the other.

    C# can also be compiled on first run, as happens in ASP.NET, which makes it close to interpreted in that case (though it's still compiled to IL and then jitted in this case). Certainly, it has pretty much all the advantages of interpreted in this case (compare with VBScript or JScript used in classic ASP), along with much of the advantages of compiled.

    Strictly, no language is jitted, interpretted or compiled qua language. We can NGen C# to native code (though if it does something like dynamically loading an assembly it will still use IL and jitting). We could write an intepretter for C or C++ (several people have done so). In its most common use case though, C# is compiled to IL which is then jitted, which is not quite the classic definition of interpreted nor of compiled.

提交回复
热议问题