intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Bài giảng Lập trình C# 2010: Chương 3 - ĐH Công nghệ Đồng Nai

Chia sẻ: Na Na | Ngày: | Loại File: PPTX | Số trang:47

106
lượt xem
18
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Bài giảng Lập trình C# 2010: Chương 3 trình bày các nội dung về Data type, Operator, Variables, Statements, Exception (Kiểu dữ liệu, điều hành, biến, báo cáo, ngoại lệ) như khái niệm, cấu trúc, câu lệnh, thao tác thực hiện và một số nội dung khác.

Chủ đề:
Lưu

Nội dung Text: Bài giảng Lập trình C# 2010: Chương 3 - ĐH Công nghệ Đồng Nai

  1. DONG NAI UNIVERSITY OF TECHNOLOGY
  2. 2 Format Code DONG NAI UNIVERSITY OF TECHNOLOGY Format Description  Code C or c Formats the string as currency. Precedes the number with an appropriate currency symbol ($ in the US). D or d Formats the string as a decimal. Displays number as an integer. N or n Formats the string with commas and two decimal places.
  3. 3 Format Code DONG NAI UNIVERSITY OF TECHNOLOGY Format  Description Code E or e Formats the number using scientific notation with a default of six decimal places F or f Formats the string with a fixed number of decimal places (two by default). G or g General. Either E or F. X or x Formats the string as hexadecimal.
  4. DONG NAI UNIVERSITY OF TECHNOLOGY
  5. DONG NAI UNIVERSITY OF TECHNOLOGY Logical and Conditional Operators
  6. DONG NAI UNIVERSITY OF TECHNOLOGY 1 2 Logical Conditional AND(&) AND (&&) 3 4 Logica Conditional l OR (|) OR (||) 5 6 Logical exclusive Logical NOT OR or XOR (!) (^)
  7. DONG NAI UNIVERSITY OF TECHNOLOGY Used to add multiple conditions to a statement
  8. DONG NAI UNIVERSITY OF TECHNOLOGY exp1 exp2 exp1 && exp2 false false false false true false true false false true true true Truth table for the &&  (logical AND) operator.
  9. DONG NAI UNIVERSITY OF TECHNOLOGY Exp1 exp2 exp1 || exp2 false false false false true true true false true true true True Truth table for the ||  (logical OR) operator.
  10. DONG NAI UNIVERSITY OF TECHNOLOGY exp1 exp2 exp1 ^ exp2 false false false false true true true false true true true false Truth table for the logical  exclusive OR (^) operator.
  11. DONG NAI UNIVERSITY OF TECHNOLOGY expression !expression false true True false Truth table for operator!  (logical NOT).
  12. DONG NAI UNIVERSITY OF TECHNOLOGY Control Structures • Program of control – Program performs one statement then goes to next line • Sequential execution
  13. DONG NAI UNIVERSITY OF TECHNOLOGY – Different statement other than the next one executes • Selection structure – The if and if/else statements • Repetition structure – The while and do/while loops – The for and foreach loops
  14. DONG NAI UNIVERSITY OF TECHNOLOGY total = total + grade; add grade to total counter = counter + 1; add 1 to counter Flowcharting C#’s sequence structure.
  15. DONG NAI UNIVERSITY OF TECHNOLOGY if Selection Structure Ø Causes the program to make a selection Ø Chooses based on conditional • Any expression that evaluates to a bool type • True: perform an action • False: skip the action Ø Single entry/exit point Ø Require no semicolon in syntax
  16. DONG NAI UNIVERSITY OF TECHNOLOGY if Selection Structure true conditions do something false
  17. If/else Selection DONG NAI UNIVERSITY OF TECHNOLOGY Ø Structure Alternate courses can be taken when the statement is false Ø Rather than one action there are two choices Ø Nested structures can test many cases Ø Structures with many lines of code need braces ({) • Can cause errors ü Fatal logic error ü Nonfatal logic error
  18. DONG NAI UNIVERSITY OF TECHNOLOGY If/else Selection Structure false true Conditions do something else do something
  19. DONG NAI UNIVERSITY OF TECHNOLOGY Conditional Operator (?:) C#’s only ternary operator Similar to an if/else structure The syntax is: boolean value ? if true : if false MessageBox.Show(dtb>=5? “Dau”: “Rot”);
  20. Loops DONG NAI UNIVERSITY OF TECHNOLOGY Ø Repeating a series of instructions Ø Each repetition is called an iteration Ø Types of Loops o Do ü Use when the number of iterations is unknown o For ü Use when the number of iterations known
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2