ậ L p trình trên Windows v iớ Microsoft® .NET
Giảng viên : Hồ Hoàn
Kiếm
Nội dung môn học
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 .
Giới thiệu Microsoft.NET.
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 .
Microsoft .NET Framework Architecture
C++
C#
…
i
Microsoft JScript®
Microsoft Visual Basic® .NET
Common Language Specification
i
Framework Class Library
M c r o s o f t V s u a
l
S
i
Common Language Runtime
t u d o®
.
N E T
Windows
LINUX
.NET Platform
Developer Tools
Devices
Servers
XML Web Services
User Experiences
Programming Services
.NET Framework .NET Framework
Class Library Class Library
Visual Basic Application s
Data Types
ADO.NET
Visual C# Applications
Web Services
.NET Platfor m Code
Windows
JIT compiler produces JIT compiler produces machine language machine language
Visual C++ Application s
Source code Source code compiles as MSIL compiles as MSIL
Common Language Common Language Runtime Runtime
Các đặc điểm của Visual Studio .NET
Web Forms Web Forms Tools Tools
Windows Windows Forms Tools Forms Tools
Visual Studio .NET
Multiple Multiple Languages Languages
Error Error Handling Handling
Data Access Data Access
XML Web XML Web Services Tools Services Tools
One-stop Application Development
Design Design Design Design
Develop Develop Develop Develop
Debug Debug Debug Debug
Deploy Deploy Deploy Deploy
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…)
MSIL, JIT và CLR
VBVB C++C++ C#C# JScript JScript J#J#
Common Language Specification Common Language Specification
Microsoft Intermediate Language (MSIL) Microsoft Intermediate Language (MSIL)
Just In-Time Compiler (JIT) Just In-Time Compiler (JIT)
Common Language Runtime (CLR) Common Language Runtime (CLR)
Operating System Operating System
Thực thi một chương trình .Net
C# Code C# Compiler
IL
Visual Basic Code
Visual Basic Compiler
JIT Compile r
COBOL Code COBOL Compiler
Native Code
Thực thi các chương trình .NET
Machine code
MSIL + Metadata
Code executed
.NET source code
C L R
C o m p
i
le r
L a n g u a g e
2nd Compilation
1st Compilation
Microsoft Intermediate Language
Machine code
MSIL + Metadata
Code executed
.NET source code
MSIL
C L R
C o m p
i
le r
L a n g u a g e
Helps Language interoperability
MSIL converted to CPU-specific code by CLR
IL is not bytecode, but is very close to it. Therefore, when the application is executed, the IL to machine code conversion is quick! CPU-independent set of instructions
Machine code
Code executed
.NET source code
CLR
C L R
MSIL + Metadat a
C o m p
i
le r
L a n g u a g e
Manages memory
Cross-language integration (especially cross- language inheritance) Makes it easy to design components & applications whose objects interact across languages
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 :