Danh mục

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

Số trang: 47      Loại file: pptx      Dung lượng: 652.38 KB      Lượt xem: 14      Lượt tải: 0    
10.10.2023

Phí tải xuống: 6,000 VND Tải xuống file đầy đủ (47 trang) 0
Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

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.
Nội dung trích xuất từ tài liệu:
Bài giảng Lập trình C# 2010: Chương 3 - ĐH Công nghệ Đồng NaiDONG NAI UNIVERSITY OF TECHNOLOGY 2 Format Code DONG NAI UNIVERSITY OF TECHNOLOGYFormat DescriptionCodeC 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 Format Code DONG NAI UNIVERSITY OF TECHNOLOGYFormat DescriptionCodeE or e Formats the number using scientific notation with a default of six decimal placesF 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.DONG NAI UNIVERSITY OF TECHNOLOGY DONG NAI UNIVERSITY OF TECHNOLOGY Logical andConditional Operators 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 (!) (^) DONG NAI UNIVERSITY OF TECHNOLOGY Used to add multipleconditions to a statement DONG NAI UNIVERSITY OF TECHNOLOGYexp1 exp2 exp1&&exp2false false falsefalse true falsetrue false falsetrue true true Truthtableforthe&& (logicalAND)operator. DONG NAI UNIVERSITY OF TECHNOLOGYExp1 exp2 exp1||exp2false false falsefalse true truetrue false truetrue true True Truthtableforthe|| (logicalOR)operator. DONG NAI UNIVERSITY OF TECHNOLOGYexp1 exp2 exp1 ^ exp2false false falsefalse true truetrue false truetrue true false Truthtableforthelogical exclusiveOR(^)operator. DONG NAI UNIVERSITY OF TECHNOLOGYexpression !expressionfalse trueTrue false Truthtableforoperator! (logicalNOT). DONG NAI UNIVERSITY OF TECHNOLOGY Control Structures• Program of control – Program performs one statement then goes to next line • Sequential execution 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 DONG NAI UNIVERSITY OF TECHNOLOGY total = total + grade;add grade to total counter = counter + 1;add 1 to counterFlowcharting C#’s sequencestructure. 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 DONG NAI UNIVERSITY OF TECHNOLOGY if Selection Structure trueconditions do somethingfalse 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 DONG NAI UNIVERSITY OF TECHNOLOGY If/else Selection Structure false true Conditionsdo something else do something DONG NAI UNIVERSITY OF TECHNOLOGY Conditional Operator (?:)C#’s only ternary operatorSimilar to an if/elsestructureThe syntax is: boolean value ? if true : if false MessageBox.Show(dtb>=5? “Dau”: “Rot”); 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 ...

Tài liệu được xem nhiều:

Gợi ý tài liệu liên quan: