Table of Contents....5
About the Author....25
About the Technical Reviewer....26
Acknowledgments....27
Chapter 1: Getting Ready....28
C# Language....28
Whom Is This Book For....29
How the Book Differs from Others....29
How to Work with the Book....30
What to Install on Your Computer....31
Development Environment....31
Visual Studio....32
Windows Versions....32
Non-Windows Operating Systems....33
Installation....34
Free Registration....34
Updates and Feedback....35
Summary....36
Part I: Data....37
Chapter 2: Your First Program....38
Seeing It in Action....38
Creating the Project....38
Launching Visual Studio....39
Creating New Project....41
Writing the Program Code....42
The Look of the Development Environment....42
Knowing Where to Write Statements....44
Writing the Code....44
Understanding Your First Statements....46
Using IntelliSense....47
Saving the Project....47
Launching Your Program....48
Note....50
Changing Text Size....50
Dealing with Errors....51
Finishing Your Work....53
Restoring Your Work....53
Transferring Your Work....56
Using Solution Explorer....56
Summary....59
Chapter 3: Dealing with Output....60
Producing Numeric Output....60
Task....60
Solution....61
Discussion....62
Making Calculations....62
Task....62
Solution....63
Note....63
Making More Complex Calculations....63
Task....63
Solution....63
Discussion....64
Joining Text....65
Task....65
Solution....66
Outputting Special Characters....66
Task....66
Solution....67
Discussion....68
Using Preformatted Text....68
Task....69
Solution....69
Note....69
Adding 1 and 1....69
Task....69
Solution....70
Discussion....71
Summary....71
Chapter 4: Using Variables....72
Storing Text....72
Task....72
Solution....72
Discussion....73
Variable Declaration....73
Alternative....73
Assignment Statement....74
Storing Numbers....74
Task....74
Solution....74
Adding 1 and 1....75
Task....75
Solution....75
Discussion....76
Doing Calculations with Variables....76
Task....76
Solution....76
Discussion....77
Assembling a Grand Combination....77
Task....78
Solution....78
Discussion....79
Working with Decimal Numbers....79
Task....79
Solution....79
Discussion....80
Working with Logical Values....81
Task....81
Solution....81
Discussion....81
Summary....82
Chapter 5: Working with Objects....83
What Time Is It?....83
Task....83
Solution....84
What Date Is It Today?....84
Task....84
Solution....85
Working with Date Components....86
Task....86
Solution....86
Using Namespaces....87
Important using....87
Namespaces....89
Without usings....90
C# 9.0 Minimalistic Program....91
Using the Environment Object....94
Task....94
Solution....94
Summary....95
Chapter 6: Using Object Actions....97
Displaying the Month in Text....97
Task....97
Solution....98
Discussion....98
Displaying Tomorrow....98
Task....99
Solution....99
Displaying a Specific Date....100
Task....100
Solution....100
Rolling a Single Die....101
Task....101
Solution....101
Note....102
Rolling Two Dice....102
Task....102
Solution....103
Getting the Path to the Desktop....104
Task....105
Solution....105
Enumeration....106
Summary....107
Chapter 7: More About Objects....108
Text as an Object....108
Task....108
Solution....109
Discussion....109
Numbers as Objects....110
Task....110
Solution....111
Discussion....111
Formatting Numbers....112
Task....113
Solution....113
Localized Output....114
Task....114
Solution....115
Concluding Notes....116
Static Objects....116
Classes....117
Relation Between Class and Object....117
Special Classes....117
Structures....118
Summary....118
Part II: Calculations....119
Chapter 8: Input....120
Text Input....120
Task....120
Solution....121
Better Input....121
Task....121
Solution....122
Discussion....122
Numeric Input....122
Task....122
Solution....123
Discussion....124
Calculation with Entered Number....124
Task....124
Solution....125
Ten More....125
Task....125
Solution....126
Addition....126
Task....127
Solution....127
Incorrect Input....128
Task....128
Solution....128
What Happened....130
Interior of the catch Part....130
Complete Solution....130
Testing....131
Explanation....131
Summary....132
Chapter 9: Numbers....133
Decimal Input....133
Task....133
Solution....134
Localized Numeric Input....134
Task....135
Solution....135
Testing and Conclusions....136
Test with a Decimal Point....136
Test with a Decimal Comma....137
Further Conclusions....137
Basic Arithmetic....138
Task....138
Solution....138
Mathematical Functions....139
Task....139
Solution....140
Discussion....141
Integer Division....141
Task....142
Solution....143
Discussion....144
Summary....144
Chapter 10: Economic Calculations....146
Currency Conversion....146
Task....146
Solution....147
Total Price....147
Task....147
Solution....148
Discussion....149
Commissions....149
Task....150
Solution....150
Discussion....151
Rounding....152
Task....152
Solution....153
Further Rounding....154
Task....154
Solution....156
Discussion....158
Value-Added Tax....158
Task....158
Analysis....158
Solution....159
Summary....160
Chapter 11: Calculations with Dates....161
Date Input....161
Task....161
Solution....162
Discussion....163
Single Month....163
Task....163
Solution....163
Discussion....164
Quarter....165
Task....165
Analysis....166
Quarter’s Number....166
Quarter’s First Month Number....166
First and Last Days....166
Solution....167
Date Difference....167
Task....168
Solution....168
Time Zones and UTC....169
Task....169
Solution....170
Summary....171
Chapter 12: Understanding Different Kinds of Numbers....172
More Numeric Types....172
Task....172
Solution....173
Note....174
Discussion....174
Unsigned Numbers....174
Decimal Numbers....175
Special Type decimal....175
Memory Consumption....176
Task....176
Solution....177
Connections....177
Discussion....178
Overflow....178
Task....179
Solution....179
Discussion....180
Dealing with Overflow....180
Task....180
Solution....181
Note....182
Settings in Visual Studio....182
Results....184
First Alternative....185
Other Alternatives....185
Summary....185
Chapter 13: Accumulating Values....187
Ten More, Revisited....187
Task....188
Solution....188
Discussion....188
Compound Assignment....189
Task....189
Solution....189
Note....189
Further Compound Assignments....190
Task....190
Solution....190
Note....191
Incrementing and Decrementing....191
Task....191
Solution....192
Compound Assignment and Text....193
Task....193
Solution....193
Progressive Summation....194
Task....194
Solution....195
Multiple Text Join....196
Task....196
Solution....197
Note....198
Summary....198
Part III: Conditionals....199
Chapter 14: Essential Tools....200
IntelliSense....200
Exploring the Possibilities....200
Examples....201
Note....204
Keyboard Shortcuts....204
Documentation....205
docs.microsoft.com....205
Search....206
Specific Class Page....207
Common Search....209
Debugging Tools....210
Project....210
Stepping Through the Code....210
Terminate Stepping....211
Breakpoints....212
Using a Breakpoint....213
Removing a Breakpoint....213
Memory Inspection....213
C# Interactive....215
What Is It?....216
How to Launch It?....216
Notes....217
Summary....218
Chapter 15: Getting Started with Conditions....219
Password Input....219
Task....219
Analysis....220
The Program....220
Program Branching....221
Syntax....222
Solution....222
Discussion....223
Test....223
Reversed Condition....223
Task....223
Solution....223
Discussion....224
Length Check....224
Task....224
Solution....225
Note....226
Positive Numbers....226
Task....226
Solution....227
Discussion....228
Odd and Even Numbers....229
Task....229
Solution....230
Case Indifference....230
Task....231
Solution....231
Without Braces....232
Task....233
Solution....233
Greater of Two Numbers....233
Task....234
Solution....234
Without the else Branch....235
Task....235
Solution....236
Using a Built-in Function....236
Task....237
Solution....237
Summary....237
Chapter 16: Practical Conditions....239
Appending Extension....239
Task....239
Solution....240
Discussion....240
Extension Detection....241
Entering a Condition....241
Missing else Branch....241
Chaining....242
Head and Tail....242
Task....242
Solution....242
Discussion....243
Deadline Check....243
Task....243
Solution....244
Discussion....245
Invoice Date Check....245
Task....245
Solution....246
Discussion....247
Spanish Day of Week....247
Task....247
Solution....248
Discussion....249
Switch Statement....250
Task....250
Solution....250
Discussion....252
Summary....252
Chapter 17: Compound Conditions....253
Yes or No....253
Task....253
Solution....254
Discussion....255
Username and Password....255
Task....255
Solution....256
Discussion....257
Two Users....257
Task....258
Solution....258
Discussion....259
Precalculation of Conditions....259
Task....259
Solution....260
Discussion....261
Yes or No Reversed....261
Task....261
Solution....261
Discussion....262
Grade Check....262
Task....262
Solution....263
Better Range Check....264
Task....264
Solution....264
Summary....265
Chapter 18: Multiple Conditions....267
Soccer....267
Task....267
Analysis....268
Solution....270
Soccer Alternatively....271
Analysis....271
Solution....272
Minimum of Three Numbers....273
Task....273
Analysis....273
Solution....274
Minimum with Built-in Function....275
Solution....275
Linear Equation....276
Task....276
Analysis....276
Solution....277
Quadratic Equation....278
Task....278
Analysis....279
Solution....280
Discussion....281
Test....281
Summary....281
Chapter 19: Advanced Conditions....282
Conditional Operator....282
Task....282
Solution....283
Discussion....283
The Program....283
Terminology....283
Summary Evaluation....284
Task....284
Details....284
Solution....285
Discussion....288
Grade Inputs....288
Program Termination....288
Yes/No Input....288
Beware of Integer Division!....289
Decimal Arithmetic....289
Second Character Test....289
Task....289
Solution....291
Discussion....291
Getting the Character....292
Existence Test....292
An Experiment....292
Summary....293
Part IV: Loops....294
Chapter 20: First Loops....295
Repeating the Same Text....295
Task....295
Solution....296
Solution Using a Loop....297
Solution....297
How the for Loop Works....297
The Loop....299
Explore It Yourself....299
Tip....299
Choosing the Number of Repetitions....299
Task....299
Solution....300
Discussion....301
Throwing a Die Repeatedly....301
Task....301
Solution....302
Repeating Similar Lines....302
Task....302
Solution Without a Loop....303
Solution Using a Loop....304
Discussion....304
Control Variable....304
The Loop Starts at 1....305
Summary....305
Chapter 21: Improving Loops....306
Choosing Text....306
Task....306
Solution....307
Alternating Loop....307
Task....307
First Solution....308
Note....309
Second Solution....309
Notes....310
Third Solution....310
Rock-Scissors-Paper....311
Task....311
Solution....312
Discussion....314
Summary....314
Chapter 22: Number Series....316
Every Other....316
Task....316
Solution....317
Discussion....318
Alternative Solution....318
Descending Series....318
Task....318
Solution....319
Discussion....320
Decimal Numbers....320
Task....320
Seemingly Correct Solution....321
Testing....322
The Cause of the Error....322
Correct Solution....323
Second Powers....324
Task....324
Solution....325
Two in a Row....325
Task....325
Solution....326
Two Independent Series....327
Task....327
Solution....328
Discussion....329
Summary....329
Chapter 23: Unknown Number of Repetitions....331
Entering a Password....331
Task....331
Solution....332
do-while Construction....333
This Case....333
Variable Outside of the Loop....333
Tip....333
Waiting for Descend....333
Task....334
Solution....334
Discussion....335
Every Week Until the End of Year....335
Task....335
Solution....336
As Long As the Number Six Is Being Thrown....337
Task....337
Solution....338
Until the Second Six....339
Task....339
Solution....340
Until Two Sixes in a Row....340
Task....341
Solution....341
Summary....342
Chapter 24: Accumulating Intermediate Results....344
Sum of the Entered Numbers....344
Task....344
Solution....345
Product of the Entered Numbers....345
Task....346
Solution....346
Discussion....347
The Greatest....347
Task....347
Solution....348
The Second Greatest....349
Task....349
Solution....350
Output of All Entered Names....352
Task....352
Solution....352
Discussion....354
Summary....354
Chapter 25: Advanced Loops....355
Thank God It’s Friday (TGIF)....355
Task....355
Solution....356
Discussion....356
While Loop....357
This Case....357
TimeSpan Object....357
Power....357
Task....357
Solution....358
Sine....359
Task....359
Analysis....359
Infinite Series....360
Series Members....360
Factorial....360
Power....360
Solution....361
Enhancement....362
Moon Landing....362
Task....362
Physical Model....364
Solution....365
Summary....367
Personal Notes....367
Dice....368
The Sine Task....368
Moon Landing....368
Concluding Wish....369
Index....370
In this book, you will learn how to create real programs. To do this, you need to learn a programming language that gives instructions to the computer. Programming languages allow computers and humans to interact. They are strict enough for computers to understand, but they are also human enough for programmers to write code.Over time, many programming languages have been developed. Each has its own strengths and weaknesses. For this book, we will be using the C# language. It is my favorite language for both professional development and teaching. It was created about 20 years ago, so the developers avoided some of the flaws of older languages. It has also been tested over time and is not likely to be replaced by a new language soon.C# is the flagship language of Microsoft and is quite versatile. You can use it for many different projects.To write a variety of programs, ranging from traditional console and desktop applications, through websites and services, to mobile development, for both business and entertainment. Originally developed on Windows, it has quickly spread to other platforms in recent years, such as Linux, Mac, Android, and iOS.