Introduction to .NET Framework Po Feng, Tsai
How a program is composed and executed Written by you but executed by a machine (computer) For programmers C,C++,Fortran,Basic For machines Architecture dependent instruction set (in binary forms) Translation is required
How a program is composed and executed Source Codes Compiler Assembler Object Codes Linker Loader Assembly Codes Hardware Architecture
Problems for a programmer Platform dependent Windows ? Linux ? Architecture dependent X86 ? ARM? PPC? Interfacing with each others An isolated virtual framework layer
The .NET Framework To provide a convenient and united development and execution environment C#, VB.NET, C++.NET & Jscript.NET CLR (Common Language Runtime) FCL (framework class library) Languages integration CTS (Common Type System) CLS (Common Language Specification) CLR
The .NET Framework Framework class library Lower level: (Base class library) Core data type (integer, string, float, object) Fundamental constructs (collection, I/O …) Access to resources (Networking, file system…) Interface to core execution (Threading, debugging …) Upper level: SQL ADO.NET XML Web services
The .NET Framework
Compilation Source codes are compiled into MSIL (MS Intermediate Language) for the first step Metadata is used to keep the content information, such as parameters, methods, of the file
Execution CLR is the execution engine of .NET framework application Virtual machine It manages the following services Code management Memory management Conversion IL into native code Exception handling Debugging
Compilation & Execution
JIT (Just In Time) Very popular technique used in various virtual machines Machine codes are generated Fast Compiles as needed
Introduction to C# Po Feng, Tsai
Getting started Visual C# 2005 Express http://www.microsoft.com/taiwan/vstudio/express/visualcsharp/ System Requirements: Processor Minimum: 600 megahertz (MHz) Pentium processor Recommended: 1 gigahertz (GHz) Pentium processor RAM Minimum: 192 megabytes (MB) Recommended: 256 MB Hard Disk: Up to 1.3 GB of available space may be required
About C# C# is announced in July 2000 C# includes the support for structured, component-based, object-oriented programming Very easy to use Modern programming
Example 1: HelloWorld In the console window: Hello World
The Class A type defines a thing including its properties and behaviors A class is used to define a new type Blueprints
The Method Behaviors are defined by methods A method is a function owned by your class Defines what you can do or how it behaves Usually you can tell what it is for from its name WriteLine()
The Method Declare a method The program entry function Keyword: void Main() The program ends when Main() exits
The comments You can add your own comments by // /* ……… */ /// (used by Visual Studio)
Namespace Tremendous number of types of the .NET Framework Class Library Each class in C# must have a unique name Name collision Example (two engineers) Jim: Science.software.engineer Charlotte: transportation.train.engineer System.Console.WriteLine(); Keyword: using using System; using System.Console; (does not compile !)
Console object This is a console program No GUIs Monitor is managed by an Console object It has many behaviors (methods) WriteLine() Write() Console.WriteLine()
The Dot operator ( . ) You can use the dot operator to access a method (or data) of a class or object You can use the dot operator to specify the sub-namespace Please keep in mind: C# is case-sensitive
The static keyword It is used to indicate that you can invoke Main() without first creating an object of type HelloWorld This issue will be covered in later sections
Developing the HelloWorld Console mode (start cmd) Need .NET Framework SDK csc HelloWorld Use Visual Studio .NET (Integrated Development Environment)
Using VS .NET File New Project Select “Console Application”
Using VS .NET
Compile & Run Compile Run Build Build Solution Ctrl+shift+B Debug Start Without Debugging F5 (debug) or Ctrl-F5
HelloWorld.exe Contains op-codes written in MSIL Read-only segment Inserted with standard win32 executable header Jumps to the JIT compiler JIT compiler Generating native instructions (like a normal exe file)