Foundations of .Net Programming with C# Haiming Chen Department of Computer Science Ningbo University Fall Semester , 2016-2017 Course 106F22A01
Operating System (MS Windows) .Net Framework Visual Studio .NET Common Language Runtime (CLR) Base Class Library: IO, Drawing, Threading Data and XML XML Web services Windows Forms Web Forms Common Language Specification (CLS) VB C++ C# … JScript Operating System (MS Windows) .Net Framework Class Library (FCL) Just In Time compilation (JIT)
CLS Define common rules that should be obeyed by all the .Net programming languages (i.e. C#, VB) Develop applications that can inter-operate with applications with different programming languages CTS (Common Type System) Standard data type Rule sets
Program w/o the .Net Framework Results C++ VB Compiler Executable code R U N T I M E
Program with the .Net Framework IL_0000: nop IL_0001: call IL_0006: nop IL_0007: ldc.i4.0 IL_0008: call IL_000d: nop IL_000e: ldnull IL_000f: ldftn IL_0015: newobj IL_001a: call IL_001f: nop IL_0020: newobj IL_0025: call IL_002a: nop IL_002b: newobj IL_0030: throw Results C++ VB Compiler Microsoft Intermediate Language (MSIL) + Meta Data CLR
Program with the .Net Framework 1st Compiling .NET source code CLR Native code MSIL Result Compiler Support inter-operation between programs written with different languages Need CLR to translate MSIL to codes running on a specific CPU (e.g. Intel, AMD, Qualcomm) IL is similar with the JAVA byte code. irrelevant to instruction sets (e.g. X86, ARM, MIPS) of CPU
Program with the .Net Framework 2nd Compiling CLR .NET source code Native code MSIL Result Compiler Memory management Together with CLS, to realize cross-language integration Ease design of components and applications, and support cross-language interaction JIT compiler:compile once, run on any number of operating systems with the .Net framework
C# language Object oriented programming language, fully utilizing the advantage of .Net Framework, for developing classic windows desktop software, web service applications Different from C/C++, which is mainly used in developing system software interacting with hardware frequently C# can also make use of functions provided by the operating system C# combines advantages of VB in fast developing software and C/C++ in power of operating low layer of system
Namespace Like package in JAVA .Net Programming with C# Namespace Like package in JAVA To organize related classes into a container To avoid conflict of naming classes Operator to use name space: using namespace a1 { class A … } namespace a2 { class A … } using a1; using a2; a1.A a2.A
Common used namespaces .Net Programming with C# Common used namespaces Namespace Description System.Drawing Process graphs, draw figures and print System.Data Operate data in database (ADO.NET) System.IO Operate file and data streaming System.Windows System.Reflection System.Threading System.Collections
Hello World Project->Properties Build->Debug/Release
Quiz 1 Please describe the procedure to run a C# source program What’s the use of CLS and CLR in .Net Framework? How does C# organize classes? How to create a project and run it in VS?