Module #: Title

Download Report

Transcript Module #: Title

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#
Microsoft
JScript®
…
Common Language Specification
Framework Class Library
Common Language Runtime
Windows
LINUX
Microsoft Visual Studio® .NET
Microsoft
Visual Basic®
.NET
.NET Platform
Developer
Tools
Devices
Servers
XML Web
Services
User
Experiences
Programming Services
.NET Framework
Visual Basic
Applications
Class Library
Data Types
Visual C#
Applications
ADO.NET
Web Services
.NET
Platform
Code
Windows
Visual C++
Applications
Source code compiles
as MSIL
Common Language
Runtime
JIT compiler produces
machine language
Các đặc điểm của Visual Studio .NET
Web Forms
Tools
Multiple
Languages
XML Web
Services Tools
Design
Windows
Forms Tools
Visual Studio .NET
One-stop Application
Development
Develop
Debug
Error
Handling
Data Access
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
VB
C++
C#
JScript
J#
Common Language Specification
Microsoft Intermediate Language (MSIL)
Just In-Time Compiler (JIT)
Common Language Runtime (CLR)
Operating System
Thực thi một chương trình .Net
C#
Code
C#
Compiler
Visual Basic
Code
VisualBasic
Compiler
COBOL
Code
COBOL
Compiler
IL
JIT
Compiler
Native
Code
MSIL
+
Metadata
CLR
.NET
source
code
Language
Compiler
Thực thi các chương trình .NET
Machine
code
2nd Compilation
1st Compilation
Code
executed
MSIL
+
Metadata
MSIL
CLR
.NET
source
code
Language
Compiler
Microsoft Intermediate Language
Machine
code
Code
executed
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
MSIL
+
Metadat
a
CLR
CLR
Language
Compiler
.NET
source
code
Machine
code
Code
executed
Manages memory
Makes it easy to design
components &
applications whose
objects interact across
languages
Cross-language
integration
(especially crosslanguage
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 …
}