Week 1 THE C LANGUAGE Chapter 1 Variables

Week 1: THE C# LANGUAGE Chapter 1: Variables and Expressions ➤Included in Visual Studio. NET ➤What the. NET Framework is and what it contains ➤ How. NET applications work ➤ What C# is and how it relates to the. NET Framework ➤ What tools are available for creating. NET applications with C# C#4. 0

Included in Visual Studio. NET l l l Visual Basic (VB. Net, VB 7. 0) C++ C# (đọc là C Sharp) J# (J Sharp). NET Framework C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 2

Install Visual Studio. NET 2010 l Chạy file setup. exe ta được hình minh họa (chú ý cài khá lâu có thể hơn 45 phút) C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 3

Install Visual Studio. NET 2010 l Trên windows XP phải Service pack 3 C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 4

Install Visual Studio. NET 2010 l Trên windows XP phải Service pack 3 Nên chọn full Chú ý C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 5

WHAT IS THE. NET FRAMEWORK? l Understanding the. NET Framework Architecture C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 6

WHAT IS THE. NET FRAMEWORK? l Common Language Runtime Architecture C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 7

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

Writing Applications Using the. NET Framework l CIL (Common Intermediate Language code. ), JIT (just-in-time compiler) l MSIL or IL (Microsoft Intermediate Language) l Assemblies Managed Code l Garbage Collection l C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 9

Writing Applications Using the. NET Framework C# Code C# Compiler Visual Basic Code Visual Basic Compiler COBOL Code COBOL Compiler C#4. 0 Windows Programming 1 IL JIT Compiler Native Code Chapter 1: Introducing C# Slide 10

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

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

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 13

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

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 15

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 16

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

SUMMARY ? ? ? C#4. 0 Windows Programming 1 Chapter 1: Introducing C# Slide 18

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 20

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

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

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

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

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

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

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

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 29

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 30

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 31

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 32

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 33

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

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

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

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

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 38

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

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 40

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 41

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

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

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

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

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

Namespaces l l l Namespaces are also used as a means of categorizing items in the. NET Framework C# code, by default, is contained in the global namespace Qualified names use period characters (. ) between namespace levels l System. Int 32 C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 47

Namespaces l Code in the global namespace, however, must refer to this name using the classified name Level. One. Name. One. C#4. 0 Windows Programming 1 Chapter 3: Variables and Expressions Slide 48

Namespaces l 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 49

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