CIS181 Week 2 - Common Language RunTime and Exercise
1 Common Language RunTime
Common Language Runtime: The .NET Framework provides a run-time environment called the Common Language Runtime, which manages the execution of code and provides services that make the development process easier.
CIS181 - Prof Chuck Konkol
2 Common Language RunTime
Compilers and tools expose the runtime's functionality and enable you to write code that benefits from this managed execution environment. Code that you develop with a language compiler that targets the runtime is called managed code; it benefits from features such as cross- language integration, cross-language exception handling, enhanced security, versioning and deployment support, a simplified model for component interaction, and debugging and profiling services.
CIS181 - Prof Chuck Konkol
3 Common Language RunTime
The runtime automatically handles object layout and manages references to objects, releasing them when they are no longer being used. Objects whose lifetimes are managed in this way by the runtime are called managed data. Automatic memory management eliminates memory leaks as well as some other common programming errors.
CIS181 - Prof Chuck Konkol
4 Common Language RunTime
The Common Language Runtime makes it easy to design components and applications whose objects interact across languages. Objects written in different languages can communicate with each other, and their behaviors can be tightly integrated. For example, you can define a class, then, using a different language, derive a class from your original class or call a method on it.
CIS181 - Prof Chuck Konkol
5 Common Language RunTime
The benefits of the runtime are as follows:
• Performance improvements. • The ability to easily use components developed in other languages. • Extensible types provided by a class library. • A broad set of language features.
CIS181 - Prof Chuck Konkol
6 Common Language RunTime
The Intermediate Language: Currently Microsoft provides compilers for C# (Pronounced as C Sharp), VisualBasic.NET, Managed C++ and JScript in their .NET Framework SDK. These compilers generate the so called Intermediate Language(IL) code which is then assembled to a Portable Executable(PE) code. The PE code is interpreted at runtime by CLR for execution. Our first example is the traditional ‘Hello World’ program written in IL. (ilhello.il)
CIS181 - Prof Chuck Konkol
7 Common Language RunTime
Creating your first program using IL (Intermediate Language) in .NET: 1. Select Start | All Programs | Accessories | Notepad 2. Enter the following IL code: .assembly HelloIL {} .method public static void Main() cil managed { .entrypoint ldstr "Hello .Net RVC Student from IL!" call void [mscorlib]System.Console::WriteLine(string) ret } 3. Select File | Save As 4. In the Save In box, select Local Disk (C:) 5. In the File Name box, type hello.il CIS181 - Prof Chuck Konkol
8 Common Language RunTime
6. In the Save As type box, select All Files and click Save. 7. Select Start | All Programs | Microsoft Visual Studio .Net | Visual Studio .Net Tools | Visual Studio .Net Command Prompt. 8. Type cd\ and press
? What is the size of the assembled hello.exe program? ______CIS181 - Prof Chuck Konkol
9 Common Language RunTime
! Congratulations! You just wrote your first .Net program in IL. Now let’s run the disasssembler to see what the assembler created.
ILDASM. The intermediate language disassembler, is a utility that takes a Portable Executable (PE) file that contains IL code and disassembles it. The code can later be reassembled using ILASM
11. Type ildasm hello.exe and press
! Congratulations! You have completed this exercise! CIS181 - Prof Chuck Konkol
10