Lập trình trên Windows với Microsoft® .NET
Gi ng viên : H Hoàn Ki mả ồ ế
Gi i thi u Microsoft.Net .ớ ệ
Gi i thi u ngôn ng C# và các khái ni m c b n.ớ ệ ữ ệ ơ ả
L p trình h ng đ i t ng v i C#.ậ ướ ố ượ ớ
L p trình Winforms v i C#.ậ ớ
L p trình c s d li u v i ADO.Net .ậ ơ ở ữ ệ ớ
N i dung môn h c ộ ọ
Kh o sát ki n trúc .Net . ả ế
Xây d ng các ng d ng v i .Net .ự ứ ụ ớ
Các thành ph n trong .Net Framework.ầ
Vai trò c a CLR và IL .ủ
Gi i thi u Microsoft.NET.ớ ệ
Microsoft .NET Framework Architecture
Windows LINUX
Common Language Runtime
Framework Class Library
Common Language Specification
Microsoft Visual Basic®
.NET C++ C# Microsoft JScript® …
Microsoft Visual Studio
® .NET
XML Web Services
Devices
Servers
User Experiences
Developer Tools
.NET Platform
.NET Framework
Common Language Common Language RuntimeRuntime
Class LibraryClass Library
Windows
Web Services
ADO.NET
Data Types
Visual Basic Applications
Visual C# Applications
Visual C++ Applications
Programming Services
.NET Platform
Code
Source code compiles as MSIL
JIT compiler producesmachine language
One-stop Application Development
Visual Studio .NET
DesignDesign DevelopDevelop DebugDebug DeployDeploy
Data AccessXML WebServices Tools
WindowsForms Tools
Web Forms Tools
Error Handling
MultipleLanguages
Các đ c đi m c a Visual Studio .NETặ ể ủ
H tr l p trình đa ngôn ng .ổ ợ ậ ữĐ c l p v i h đi u hành (Platform ).ộ ậ ớ ệ ề
Xây d ng ng d ng nhanh chóng và d dàng.ự ứ ụ ễ
H tr xây d ng ng d ng cho nhi u thi t b .ổ ợ ự ứ ụ ề ế ị
Môi tr ng thi t k tr c quan .ườ ế ế ự
H ng đ n các ng d ng trên Internet (Webservice, WAP…)ướ ế ứ ụ
Microsoft Intermediate Language (MSIL)Microsoft Intermediate Language (MSIL)
Common Language SpecificationCommon Language Specification
VBVB C++C++ C#C# JScriptJScript J#J#
Common Language Runtime (CLR)Common Language Runtime (CLR)
Just In-Time Compiler (JIT)Just In-Time Compiler (JIT)
Operating SystemOperating System
MSIL, JIT và CLR
Th c thi m t ch ng trình .Netự ộ ươ
C#Code
C#Compiler
Visual BasicCode
Visual BasicCompiler
COBOLCode
COBOLCompiler
ILJIT
Compiler
NativeCode
.NET source
code
Lang
uage
Com
pile
r MSIL+
MetadataMachine
codeCode
executedCLR
1st Compilation
2nd Compilation
Th c thi các ch ng trình .NETự ươ
Microsoft Intermediate Language
.NET source
code
Lang
uage
Com
pile
r MSIL+
MetadataMachine
codeCode
executedCLRMSIL
Helps Language interoperability
IL is not bytecode, but is very close to it. Therefore, when the application is executed, the IL to machine code conversion is quick!
MSIL converted to CPU-specific code by CLR
CPU-independent set of instructions
.NET source
code
Lang
uage
Com
pile
r MSIL+
Metadata
Machinecode
Code executedC
LRCLRManages memory
Makes it easy to design components & applications whose objects interact across languages
Cross-language integration (especially cross-language inheritance)
Compile once, and run on any CPU & OS that supports the runtime!
Visual C#.Net và các khái ni m c b nệ ơ ả
Đ c phát tri n b i Microsoft do nhóm ượ ể ở Anders Hejlsberg và Scott Wiltamuth sáng tác.
Ngôn ng l p trình tr c quan, h ng s ki n, h ng đ i ữ ậ ự ướ ự ệ ướ ốt ng.ượ
D a theo ý t ng các ngôn ng khác : C,C++, Java và ự ưở ữVisual Basic.
H tr đ y đ b i ổ ợ ầ ủ ở .Net Platform. Compiler hi u qu nh t trong ệ ả ấ .Net family. Kh năng thay th cho C++.ả ế H n ch s d ng con tr .ạ ế ử ụ ỏ
Ch ng trình C#ươ
using System;class SampleCSharp
{
static void Main(string[] args)
{
Console.WriteLine("Hello world");
}
}
Các ki u d li u trong C#ể ữ ệ
Các ki u d li u đ n gi n : ể ữ ệ ơ ả int, float, string , char, bool.. Các ki u d li u tham chi u : đ i t ng, l pể ữ ệ ế ố ượ ớ . Các b t khi s d ng v i bi n : ổ ừ ử ụ ớ ế private, public, protected Các ki u d li u khác : ể ữ ệ Array, Struct, Enum... Giá tr m c đ nh cho các ki u d li u :ị ặ ị ể ữ ệ
Nh p và xu t trong C#ậ ấ
S d ng các ph ng th c c a l p ử ụ ươ ứ ủ ớ Console trong namspace System.
Console.WriteLine()
Console.Write()
Console.ReadLine()
Console.Read ()
Ví d :ụ
using System;class SampleCSharp{ static void Main(string[] args) {
//Nhập vào 1 chuổi string s = Console.ReadLine();
//Nhập vào số nguyên int n = int.Parse(Console.ReadLine());
//In ra mà hình Console.WriteLine("s = {0} va n = {1}",s,i);
}}
C u trúc ấ If
Cú pháp :
if (bi u th c )ể ứ{
//Các câu l nh …ệ}else {//Cá câu l nh … ệ}
Recommended