Week 1 Introduce What is the NET Framework




















































- Slides: 52

Week 1: Introduce ➤What is the. NET Framework ? § CLR, MSIL, FLC § Garbage collection § Namespace ➤ What C# is and how it relates to the. NET Framework C#4. 0

WHAT IS THE. NET FRAMEWORK? l l Microsoft’s modern software development platform Programs executed by Common Language Runtime (CLR) FLC(Framework class library) Includes a large library of components (classes) which can be used in programs Supports several programming languages, including C#, Visual Basic, C++, J# C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 2

. NET Framework C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 3

. NET Framework . NET 4. 0 (2010) VS. NET 2010 Default: Windows 7. NET 3. 5 (Nov-2007) VS. NET 2008 Default: Windows 7 . NET 2. 0 (Nov-2005) VS. NET 2005 . NET 3. 0 (Nov-2006) Default: Windows Vista, Server 2008 . NET 1. 1 (Apr-2003) VS. NET 2003 Default: Server 2003 . NET 1. 0 (Feb-2002) C#4. 0 4

Writing Applications Using the. NET Framework l CLR: Common Language Runtime l MSIL or IL: Microsoft Intermediate Language l l JIT: just-In-Time compiler Assemblies Managed Code l Garbage Collection l C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 5

. NET Framework -CLR l Common Language Runtime Architecture C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 6

Writing Applications Using the. NET Framework CT C#. NET C# Compiler CT VB. NET Compiler Programmer MS IL CLR CT J#. NET CT C++. NET C#4. 0 0 101101 J#. NET Compiler C++ Compiler 7

Writing Applications Using the. NET Framework C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 8

Assembly l Managed Modules l l l Chứa IL code để thực thi Chứa resource, metadata… Portable Executable (PE) l l ly b m se Process assembly (EXE) Library assembly (DLL) C#4. 0 s A T E . N EXE DLL 9

Managed Code l Software that is written using the. NET Framework is called Managed Legacy Software (unmanaged code) Managed Executable Common Language Runtime Windows (OS khác) C#4. 0 10

Garbage collection class my. Class{ void Method(){ variable v 1; variable v 2; Managed Heap B A do{ …. E C } D } A và D sẽ bị xoá do ko còn tham chiếu hay truy cập tới C#4. 0 11

Namespaces l l l Namespaces are also used as a means of categorizing items in the. NET Framework Qualified names use period characters (. ) between namespace levels Within a namespace, you can define nested namespaces, also using the namespace keyword. C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 12

Namespaces C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 13

Namespace Description System Chứa lớp toán học, chuyển đổi dữ liệu System. IO Các lớp cho thao tác Input và Output System. Net Các lớp liên quan đến network protocol System. Collections Chức các lớp liên quan đến xử lý tập hợp System. Data Các lớp của ADO. NET System. Drawing Các lớp thực thi chức năng GUI System. Threading Các lớp lập trình Multi. Thread System. Web Các lớp liên quan đến HTTP protocol System. Xml Các lớp liên quan XML C#4. 0 14

Framework (Base) Class Library FCL/BCL l l l l l Đặc tính lõi: IL, kiểu dữ liệu trong CTS Hỗ trợ Win GUI và control Web. Form (ASP. NET) Data Access (ADO. NET) Directory Access File System, registry access Networking and web browsing. NET attributes and reflection Win. OS access COM interoperability C#4. 0 15

Run. NET App from Client l Required MS. NET Framework compatible l l Install. NET 3. 5 Full Redistributable package l l l MS. NET Framework 2. 0, 3. 5 (dotnetfx 35. exe, 197 MB) Windows Vista comes with. NET Framework 3. 0 Windows 7 comes with. NET Framework 4. 0. NE T App C#4. 0 . NET App 16

C#4. 0 17

WHAT IS C#? l Applications You Can Write with C# l l l Windows applications Web services: C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 18

Visual Studio l l l Powerful, professional Integrated Development Environment (IDE) Integrates compilers, debugger and many other useful tools for development Can work with many different types of project, including: l l Console (text-based) applications Windows (GUI) applications Web applications (ASP. NET) Class libraries C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 19

Visual Studio Solution explorer Visual designer Toolbox windows Properties windows C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 20

Visual Studio projects l l A project contains source code files, settings and resources for an application May contain references to class libraries May contain data used by application Building a project: l l Compiles source files Copies non-source files to output folder Creates an assembly in output folder Building a solution builds all its projects C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 21

Project details Solution folder contents Project folder contents References – class libraries used by this application Solution file (. sln) and project file (. csproj) are created by VS and contain solution/project configuration information C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 22

Creating a Visual Studio project l Demo C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 23

Week 1: THE C# LANGUAGE Chapter 2: Writing a C# Program Ø Ø Ø A basic working knowledge of Visual Studio 2010 and Visual C# 2010 Express Edition How to write a simple console application How to write a Windows Forms application C#4. 0

Visual C# 2010 Ultimate C#4. 0 Windows Programming 1 Chapter 2: Writing a C# Program Slide 25

CONSOLE APPLICATIONS C#4. 0 Windows Programming 1 Chapter 2: Writing a C# Program Slide 26

WINDOWS FORMS APPLICATIONS l MO_BAI 1 C#4. 0 Windows Programming 1 Chapter 2: Writing a C# Program Slide 27

The Solution Explorer C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 28

The Properties Window C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 29

Code view C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 30

The Error List Window C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 31

SUMMARY ? ? ? C#4. 0 Windows Programming 1 Chapter 2: Writing a C# Program Slide 32

Week 1: THE C# LANGUAGE Chapter 3: Variables and Expressions ü ü ü Basic C# syntax Variables and how to use them Expressions and how to use them C#4. 0

BASIC C# SYNTAX l l The look and feel of C# code is similar to that of C++ and Java. C# compilers ignore additional spacing in code, whether it results from spaces, carriage returns, or tab characters (collectively known as whitespace characters). Statements C# is a block-structured language, meaning statements are part of a block of code. C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 34

block l These blocks, which are delimited with curly brackets ({ and }), may contain any number of statements, or none at all C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 35

comments l l l Comments can be created using //… Multi-lines comments use /* … */ You can use single-line comments that start with three / symbols instead of two /// A special comment l l Comments are ignored by the compiler Used only for human readers C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 36

The code outlining l You can do this with the #region and #endregion keywords, which define the start and end of a region of code that can be expanded and collapsed. C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 37

VARIABLES l C# syntax for declaring variables merely specifies the type and variable name: <type> <name>; int. Number. Of. Students; l Declaration includes l l Name, follow Naming Convention Rules Data Type Required Value for Constants Optional Initial Value for Variables C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 38

Simple Types C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 39

Simple Types C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 40

Simple Types C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 41

Using Simple Type Variables l Mo_b 3 C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 42

Variable Naming l l The first character of a variable name must be either a letter, an underscore character ( _ ), or the at symbol (@). Subsequent characters may be letters, underscore characters, or numbers. C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 43

String Literals C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 44

String Literals l l l This means that the following strings are equivalent: "Karli ’s string. " "Karli u 0027 s string. “ @ "A short list: item 1 item 2“ "C: \Temp\My. Dir\My. File. doc“ @ "C: TempMy. DirMy. File. doc" C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 45

EXPRESSIONS l l Operators can be roughly classified into three categories: ➤ Unary— Act on single operands ➤ Binary—Act on two operands ➤ Ternary—Act on three operands C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 46

Mathematical Operators C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 47

C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 48

Manipulating Variables with Mathematical Operators C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 49

Assignment Operators C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 50

Operator Precedence C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 51

SUMMARY ? ? ? C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 52