Managed vs. Unmanaged Code


In general, when you write a C# program, you are creating what is called managed code. Managed code is executed under the control of the Common Language Runtime as just described. Because it is running under the control of the CLR, managed code is subject to certain constraints—and derives several benefits. The constraints are easily described and met: the compiler must produce an MSIL file targeted for the CLR (which C# does) and use the .NET Framework class library (which C# does). The benefits of managed code are many, including modern memory management, the ability to mix languages, better security, support for version control, and a clean way for software components to interact.

The opposite of managed code is unmanaged code. Unmanaged code does not execute under the Common Language Runtime. Thus, all Windows programs prior to the creation of the .NET Framework use unmanaged code. It is possible for managed code and unmanaged code to work together, so the fact that C# generates managed code does not restrict its ability to operate in conjunction with preexisting programs.

The Common Language Specification

Although all managed code gains the benefits provided by the CLR, if your code will be used by other programs written in different languages, then for maximum usability, it should adhere to the Common Language Specification (CLS). The CLS describes a set of features that different languages have in common. CLS compliance is especially important when creating software components that will be used by other languages. The CLS includes a subset of the Common Type System (CTS). The CTS defines the rules concerning data types. Of course, C# supports both the CLS and the CTS.




C# 2.0(c) The Complete Reference
C# 2.0: The Complete Reference (Complete Reference Series)
ISBN: 0072262095
EAN: 2147483647
Year: 2006
Pages: 300

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net