1. Trang chủ
  2. » Công Nghệ Thông Tin

BKIndex dotnet lecture01 session1 module1 2 3 4 5 operators constructs arrays

39 84 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 39
Dung lượng 601 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Programming in C# / Chapter 1/ 2 of 39Objectives  Explain the need for C#  Discuss flow control of a C# program  Explain the fundamental data types in C#  Discuss the concept of Boxi

Trang 1

Chapter 1

Trang 2

Programming in C# / Chapter 1/ 2 of 39

Objectives

 Explain the need for C#

 Discuss flow control of a C# program

 Explain the fundamental data types in C#

 Discuss the concept of Boxing and UnBoxing

 Discuss Structures in C#

 Discuss Enumeration types

 Compile and run a C# program

Trang 3

Programming in C# / Chapter 1/ 3 of 39

Microsoft net

 Represents a new platform for developing

windows & web applications

 Supports more than 20 languages

 Revolutionizes facilities available for Windows programming

Trang 4

Programming in C# / Chapter 1/ 4 of 39

Introduction to C#

 Takes full advantage of the net Platform

 The most efficient compiler in the net family

 A modern replacement for C++

 Enhances developer productivity and increases safety, by enforcing script type checking

 Allows restricted use of native pointers

Trang 5

Programming in C# / Chapter 1/ 5 of 39

C# Program Flow

 A simple C# program:

Trang 6

Programming in C# / Chapter 1/ 6 of 39

C# Constructs (1)

 Variables in C# are declared as follows:

Trang 7

Programming in C# / Chapter 1/ 7 of 39

Trang 8

Programming in C# / Chapter 1/ 8 of 39

Trang 9

Programming in C# / Chapter 1/ 9 of 39

Default Values (2)

 The default values of the common data types:

Trang 10

Programming in C# / Chapter 1/ 10 of 39

Trang 11

Programming in C# / Chapter 1/ 11 of 39

 The highlighted line acts as a placeholder where the value of the specified variable (result) will be displayed

Input / Output In C# (2)

Trang 12

Programming in C# / Chapter 1/ 12 of 39

 The program will accept a line from the user and echo it back as output

Input / Output In C# (3)

Trang 13

Programming in C# / Chapter 1/ 13 of 39

Trang 14

Programming in C# / Chapter 1/ 14 of 39

Trang 15

Programming in C# / Chapter 1/ 15 of 39

The switch Statement

Trang 16

Programming in C# / Chapter 1/ 16 of 39

Trang 17

Programming in C# / Chapter 1/ 17 of 39

Trang 18

Programming in C# / Chapter 1/ 18 of 39

The while loop

The while loop iterates through the

The continue statement skips the current

iteration and begins with the next

iteration

Trang 19

Programming in C# / Chapter 1/ 19 of 39

The do loop

 Syntax:

Trang 20

Programming in C# / Chapter 1/ 20 of 39

 Syntax :

Trang 21

Programming in C# / Chapter 1/ 21 of 39

 The foreach loop is used to iterate through a collection or an array

 Syntax:

Trang 22

Programming in C# / Chapter 1/ 22 of 39

 Example:

 Output:

Trang 23

Programming in C# / Chapter 1/ 23 of 39

Constructors in C#

 A constructor in C# has the same

name as

the class

Trang 24

Programming in C# / Chapter 1/ 24 of 39

Destructors in C#

 A destructor in C# also has the same name

as the class preceded by a tilde (~)

Trang 25

Programming in C# / Chapter 1/ 25 of 39

Fundamental Types Of C# (1)

 C# divides data types into two fundamental categories:

- int, char and structures

- classes, interfaces, arrays and strings

Trang 26

Programming in C# / Chapter 1/ 26 of 39

 Holds a value in the memory

 Stored in a stack

 Contains the address of

the object in the heap

 = null means that no object has been

referencedFundamental Types Of C#

(2)

Trang 27

Programming in C# / Chapter 1/ 27 of 39

Value Types

 Example:

 Output:

Trang 28

Programming in C# / Chapter 1/ 28 of 39

Reference Types

 Example:

Output:

Trang 29

Programming in C# / Chapter 1/ 29 of 39

Value types vs Reference types

Trang 30

Programming in C# / Chapter 1/ 30 of 39

Boxing & Unboxing [1]

 Boxing is the conversion of a value type

into a

reference type

 Unboxing is the conversion of a reference type into a value type

Trang 31

Programming in C# / Chapter 1/ 31 of 39

Boxing & Unboxing (2)

Trang 32

Programming in C# / Chapter 1/ 32 of 39

Data Types In C#

 C# provides a Unified Type System

 All data types in C#, are derived from just one class, the object class

Trang 33

Programming in C# / Chapter 1/ 33 of 39

Trang 34

Programming in C# / Chapter 1/ 34 of 39

Arrays

 A group of values of similar data type

 It belongs to the reference type and hence, are stored on the heap

 The declaration of arrays in C#, follow the syntax given below:

DataType [ number of elements ] ArrayName ;

int [ 6 ] arr1 ;

Trang 35

Programming in C# / Chapter 1/ 35 of 39

Structures

 Custom data Types

 Can have constructors

 Cannot implement

inheritance

 Can have methods

Trang 36

Programming in C# / Chapter 1/ 36 of 39

Enumerators (1)

 They are a set of named constants

Trang 37

Programming in C# / Chapter 1/ 37 of 39

Enumerators (2)

Enumerators in C# have numbers associated

with the values

By default, the first element of enum is assigned

a value of 0 and is incremented for each

subsequent enum element

Trang 38

Programming in C# / Chapter 1/ 38 of 39

Enumerators (3)

The default value can be overridden during

initialization

Trang 39

Programming in C# / Chapter 1/ 39 of 39

Compiling & Running

 Step 1 – Type your code in Notepad

 Step 2 – Save the file with a cs extension

 Step 3 – Switch to DOS prompt and type the following command:

Ngày đăng: 27/09/2019, 23:13

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN

w