it 374 c# and applications/ it695 c# data structuresc# treats numeric literals like 0.05 as type...

75
Module 2.4: Control Statements: Part II Xianrong (Shawn) Zheng Spring 2017 IT 374 C# and Applications/ IT695 C# Data Structures IT374/ IT695 1

Upload: others

Post on 02-Jun-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

Module 2.4: Control Statements: Part II

Xianrong (Shawn) Zheng

Spring 2017

IT 374 C# and Applications/IT695 C# Data Structures

IT374/ IT695 1

Page 2: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

Essentials of Counter-Controlled Iteration for Iteration Statement do…while Iteration Statement switch Multiple Selection Statement break and continue Statements Logical Operators

Outline

IT374/ IT695 2

Page 3: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The elements of counter-controlled iteration:1. a control variable (or loop counter),2. the control variable’s initial value,3. the control variable’s increment that’s applied during

each iteration of the loop,4. the loop-continuation condition that determines if

looping should continue.

Essentials of Counter-Controlled Iteration

IT374/ IT695 3

Page 4: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 4

Page 5: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

C# provides the for iteration statement, which specifies the elements of counter-controlled iteration in a single line of code.

for Iteration Statement

IT374/ IT695 5

Page 6: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 6

Page 7: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 7

Page 8: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The general format of the for statement isFor (initialization; loopContiuationCondition; increment){

statement}

If the initialization expression in the for header declares the control variable, the control variable can be used onlyin that for statement ─ it will not exist outside it. This restricted use of the name of the control variable is known as the variable’s scope.

for Iteration Statement (Cont.)

IT374/ IT695 8

Page 9: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

All three expressions in a for header are optional. If the loopConinuationCondition is omitted, C# assumes that it’s always true, thus creating an infinite loop.

You can omit the initialization expression if the app initializes the control variable before the loop ─ in this case, the scope of the control variable will not be limited to the loop.

You can omit the increment expression if the app calculates the increment with statements in the loop’s body or if no increment is needed.

for Iteration Statement (Cont.)

IT374/ IT695 9

Page 10: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The initialization, loop-continuation condition and increment portions of a for statement can contain arithmetic expressions.

Apps frequently display the control variable value or use it in calculations in the loop body, but this use is not required. The control variable is commonly used to control iteration without being mentioned in the body of the for.

for Iteration Statement (Cont.)

IT374/ IT695 10

Page 11: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 11

Page 12: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The initialization and increment expressions can be comma-separated lists that enable you to use multiple initialization expressions or multiple increment expressions.

App: Summing Even Integers

IT374/ IT695 12

Page 13: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 13

Page 14: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The next app uses the for statement to compute compound interest.

C# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─ unlike double values, int values can be assigned to decimal variables. When principle is initialized to 1000, the int value 1000 is promoted to type decimal implicitly ─ no cast is required.

App: Compound-Interest Calculations

IT374/ IT695 14

Page 15: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 15

Page 16: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 16

Page 17: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 17

Page 18: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

Many classes also provide methods to perform common tasks that do not require specific objects ─ they must be called using a class name. Such methods are called static methods. You’ve used several static methods of class Console ─ methods Write, WriteLine and ReadLine.

You call a static method by specifying the class name followed by the member-access operator(.) and the method name, as in ClassName.MethodName (arguments)

App: Compound-Interest Calculations (Cont.)

IT374/ IT695 18

Page 19: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

C# does not include an exponentiation operator, so we use class Math’s static method Pow to perform the compound-interest calculation. The expression Math.Pow (x, y) calculates the value of x raised to the yth power.

C# will not implicitly convert double to a decimal type, or vice versa, because of the possible loss of information in either conversion.

App: Compound-Interest Calculations (Cont.)

IT374/ IT695 19

Page 20: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The interpolation expression {year, 4} formats the year. The integer 4 after the comma indicats that the value output should be displayed with a field width of 4 ─ that is, WriteLine displays the value with at least four character positions.

If the value to be output is fewer than four character positions wide, the value is right-aligned in the field by default.

If the value to be output were more than four character positions wide, the field width would be extended to the right to accommodate the entire value.

App: Compound-Interest Calculations (Cont.)

IT374/ IT695 20

Page 21: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

Similarly, the interpolation expression {amount, 20:C} formats the amount as currency (C) right-aligned in a field of at least 20 characters. To left align value, simply use a negative field width.

Due to the imprecise nature of floating-point numbers, type double is preferred over type float, because double variables can represent floating-point numbers more precisely.

App: Compound-Interest Calculations (Cont.)

IT374/ IT695 21

Page 22: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The do…while statement tests the loop-continuation condition after executing the loop’s body; therefore, the body always executes at least once.

do…while Iteration Statement

IT374/ IT695 22

Page 23: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 23

Page 24: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 24

Page 25: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

C# provides the switch multiple-selection statement to perform different actions based on the possible values of an expression, known as the switch expression. Each action is associated with one or more of the switch expression’s possible values. These are specified as constant integral expressions or a constant string expression.

switch Multiple-Selection Statement

IT374/ IT695 25

Page 26: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

A constant integral expression is any expression involving character and integer constants that evaluates to an integer value ─ i.e., values of type sbyte, byte, short, ushort, int, uint, long, ulong and char, or a constant from an enum type.

A constant string expression is any expression composed of string literals or const string variables that always results in the same string.

switch Multiple-Selection Statement

IT374/ IT695 26

Page 27: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 27

Page 28: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 28

Page 29: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 29

Page 30: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 30

Page 31: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 31

Page 32: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 32

Page 33: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The notation Ctrl + z means to hold down the Ctrl key and tap the z key when typing in a Command Prompt. Ctrl + z is the Windows key sequence for typing the end-of-file indicator. This is one way to inform an app that there’s no more data to input. If Ctrl + z is entered while the app is awaiting input with a ReadLine method, null is returned.

The end-of-file indicator is a system-dependent keystroke combination. On many non-Windows systems, end-of-file is entered by typing Ctrl + d.

Windows typically displays the characters ^Z in a Command Prompt when the end-of-file indicator is typed.

switch Multiple-Selection Statement (Cont.)

IT374/ IT695 33

Page 34: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The switch statement consists of a block that contains a sequence of case labels and an optional default label. These are used in this example to determine which counter to increment based on the grade.

The app attempts to match the value of the switch expression with one of the case labels.

The switch expression in line 31 performs integer division, which truncates the fractional part of the result.

The break statement (line 39) causes program control to proceed with the first statement after the switch (line 51).

switch Multiple-Selection Statement (Cont.)

IT374/ IT695 34

Page 35: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

Listing case labels consecutively in this manner with no statements between them enables the cases to perform the same set of statements.

Each case can have multiple statements. The switch statement differs from other control statements in that it does not require braces around multiple statements in each case.

switch Multiple-Selection Statement (Cont.)

IT374/ IT695 35

Page 36: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

If no match occurs between the switch expression’s value and a case label, the statements after the default label execute.

If no match occurs and the switch does not contain a default label, program control simply continues with the first statement (if there’s one) after the switch statement.

switch Multiple-Selection Statement (Cont.)

IT374/ IT695 36

Page 37: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

C# is different from other programming languages ─ after the statement in a case, you’re required to include a statement that terminates the case, such as a break, a return or a throw; otherwise, a compilation error occurs.

switch Multiple-Selection Statement (Cont.)

IT374/ IT695 37

Page 38: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 38

Page 39: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

In the switch statements cases, constant integral expressions can be character constants ─ specific characters in single quotes, such as ‘A’, ‘7’ or ‘$’ ─ which represent the integer values of characters.

A string constant (or string literal) is a sequence of characters in double quotes, such as “Welcome to C# Programming!” or a const string variable.

The expression in each case also can be a constant ─ a value which does not change for the entire app. Constants are declared with the keyword const.

switch Multiple-Selection Statement (Cont.)

IT374/ IT695 37

Page 40: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

Strings can be used in switch expressions, and string literals can be used in case labels.

Class AutoPolicy Case Study: strings in switch Statements

IT374/ IT695 40

Page 41: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 41

Page 42: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 42

Page 43: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 43

Page 44: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 44

Page 45: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The break statement, when executed in a while, for, do…while, switch, or foreach, causes immediate exit from the loop or switch. Execution continues with the first statement after the control statement.

break and continue Statements

IT374/ IT695 45

Page 46: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 46

Page 47: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 47

Page 48: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The continue statement, when executed in a while, for, do…while, switch, or foreach, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.

In while and do…while statements, the app evaluates the loop-continuation test immediately after the continue statement executes.

In a for statement, the increment expression normally executes next, then the app evaluates the loop-continuation test.

break and continue Statements (Cont.)

IT374/ IT695 48

Page 49: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 49

Page 50: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 50

Page 51: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

C# provides logical operators to enable you to form more complex conditions by combining simple conditions.

Suppose that we wish to ensure at some point in an app that two conditions are both true before we choose a certain path of execution. In this case, we can use the &&(conditional AND) operator.

Logical Operators

IT374/ IT695 51

Page 52: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 52

Page 53: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

Now suppose we wish to ensure that either or both of two conditions are true before we choose a certain path of execution. In this case, we use the || (conditional OR) operator.

Logical Operators (Cont.)

IT374/ IT695 53

Page 54: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 54

Page 55: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The parts of an expression containing && or || operators are evaluated only until it’s known whether the condition is true or false. This feature of conditional AND andconditional OR expression is called short-circuit evaluation.

The Boolean logical AND (&) and Boolean logical inclusive OR (|) operators work identically to the && (conditional AND) and || (conditional OR) operators, with one exception ─ the Boolean logical operators alwaysevaluate both of their operands (i.e., they do not perform short-circuit evaluation)

Logical Operators (Cont.)

IT374/ IT695 55

Page 56: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

A complex condition contains the boolean logical exclusive OR (^) operator (also called the logical XOR operator) is true if and only if one of its operands is true and the other is false. If both operands are true or false, the entire condition is false.

Logical Operators (Cont.)

IT374/ IT695 56

Page 57: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 57

Page 58: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

The ! (logical negation or not) operator enables you to “reverse” the meaning of a condition. It is a unary operator that has only a single condition as an operand.

Logical Operators (Cont.)

IT374/ IT695 58

Page 59: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 59

Page 60: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 60

Page 61: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 61

Page 62: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 62

Page 63: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 63

Page 64: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 64

Page 65: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 65

Page 66: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 66

Page 67: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

Any form of control ever needed in a C# app can be expressed in terms of sequence, the if statement (selection) and the while statement (iteration). These can be combined in only two ways ─ stacking and nesting.

Structured-Programming Summary

IT374/ IT695 66

Page 68: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 68

Page 69: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 69

Page 70: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 70

Page 71: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 71

Page 72: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 72

Page 73: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 73

Page 74: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

IT374/ IT695 74

Page 75: IT 374 C# and Applications/ IT695 C# Data StructuresC# treats numeric literals like 0.05 as type double. Similarly, C# treats whole-number literals like 7 and 1000 as type int ─

6.9, 6.10, 6.14, and 6.19 (pp. 232-190 of the textbook)

Exercises

IT374/ IT695 66