Table Of ContentIntroduction to Computer Science in C#
Release 1.0
Andrew N. Harrington and George K. Thiruvathukal
10-September-2016 16:59:25
CONTENTS
1 Context 1
1.1 MotivationforThisBook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 ResourcesOnline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 DownloadingandReadingOptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 ComputerScience,Broadly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2 C#DataandOperations 9
2.1 ASampleC#Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Lab: Editing,Compiling,andRunningwithXamarinStudio . . . . . . . . . . . . . . . . . . . . . . 13
2.3 Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.4 VariablesandAssignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.5 SyntaxTemplateTypography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.6 Strings,PartI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.7 WritingtotheConsole . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.8 C#ProgramStructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.9 CombiningInputandOutput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.10 StringSpecialCases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.11 SubstitutionsinConsole.WriteLine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.12 ValueTypesandConversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
2.13 LearningtoSolveProblems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.14 Lab: DivisionSentences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
2.15 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3 DefiningFunctionsofyourOwn 57
3.1 AFirstFunctionDefinition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
3.2 MultipleFunctionDefinitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.3 FunctionParameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
3.4 MultipleFunctionParameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.5 ReturnedFunctionValues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.6 TwoRoles: WriterandConsumerofFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
3.7 LocalScope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
3.8 StaticVariables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
3.9 NotusingReturnValues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.10 LibraryClasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
3.11 Tracebacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
3.12 StaticFunctionSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.13 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4 BasicStringOperations 83
4.1 StringIndexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
i
4.2 SomeInstanceMethodsandtheLengthProperty . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.3 ACreativeProblemSolution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
4.4 Lab: StringOperations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.5 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5 Decisions 91
5.1 ConditionsI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.2 SimpleifStatements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.3 if-elseStatements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
5.4 MoreConditionalExpressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
5.5 MultipleTestsandif-elseStatements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
5.6 If-statementPitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
5.7 CompoundBooleanExpressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
5.8 NestedifStatements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
5.9 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
6 WhileLoops 113
6.1 While-Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
6.2 While-StatementswithSequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
6.3 InteractivewhileLoops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
6.4 Short-Circuiting&&and|| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
6.5 WhileExamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
6.6 MoreStringMethods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
6.7 UserInput: UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
6.8 GreatestCommonDivisor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
6.9 Do-WhileLoops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
6.10 NumberGuessingGameLab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
6.11 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
7 ForeachLoops 153
7.1 foreachSyntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
7.2 foreachExamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
7.3 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
8 ForLoops 157
8.1 For-StatementSyntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
8.2 ExamplesWithforStatements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
8.3 Lab: Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
8.4 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
9 Files,Paths,andDirectories 177
9.1 FilesAsStreams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
9.2 WritingFiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
9.3 ReadingFiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
9.4 PathStrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
9.5 DirectoryClass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
9.6 FileClass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
9.7 CommandLineExecution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
9.8 FIOHelperClass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
9.9 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
10 Arrays 191
10.1 OneDimensionalArrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
10.2 MusicalScalesandArrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
10.3 LinearSearching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
ii
10.4 SortingAlgorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
10.5 BinarySearching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
10.6 Lab: Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
10.7 Lab: Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
10.8 Multi-dimensionalArrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
10.9 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
11 Lists 237
11.1 ListSyntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
11.2 .NetLibrary(API) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
11.3 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
12 Dictionaries 243
12.1 DictionarySyntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
12.2 DictionaryEfficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
12.3 DictionaryExamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
12.4 Lab: FileDataandCollections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
12.5 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
13 ClassesandObject-OrientedProgramming 253
13.1 AFirstExampleofClassInstances: Contact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
13.2 ClassInstanceExamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
13.3 TheRationalClass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
13.4 PlanningAClassStructure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
13.5 ClassesAndStructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
13.6 DefiningOperators(Optional) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
13.7 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
14 Testing 287
14.1 Assertions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
14.2 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
14.3 TestingtheConstructor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
14.4 TestingRationalComparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
14.5 TestingRationalArithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
14.6 TestingRationalConversions(toothertypes) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
14.7 TestingtheParsingFeature. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
14.8 RunningtheNUnitTests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
15 Interfaces 295
15.1 RationalsRevisited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
15.2 CsprojectRevisited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
15.3 ChapterReviewQuestions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
16 Recursion 305
17 DataStructures 307
18 Appendix 309
18.1 DevelopmentTools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
18.2 XamarinStudio. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
18.3 CommandLineIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
18.4 PrecedenceofOperators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
18.5 Homework: GradeCalculation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
18.6 Homework: GradeCalculationfromIndividualScores . . . . . . . . . . . . . . . . . . . . . . . . . 322
18.7 Homework: GradeFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
iii
18.8 Homework: BookList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
18.9 GroupProject. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
18.10 Lab: VersionControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
18.11 MercurialandTeamwork. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
18.12 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Bibliography 353
Index 355
iv
CHAPTER
ONE
CONTEXT
1.1 Motivation for This Book
Thisisreallyapreface,buttheotherwiseverycapableSphinxpublishingenvironmentthatweuseisnotsetupfora
separatepreface.
1.1.1 Pedagogy
Our first aim is to provide a good introduction and conceptual framework for more computer science, not an ency-
clopediccoverageofC#. C#willnotbemoststudents’onlylanguage,ornecessarilythemostused. Designingand
creatingalgorithmsinaparticularlanguageisanimportantskill,requiringongoingeffort,somostofthetextisstill
centeredonC#.
C#isanobject-orientedlanguage. Thereistheongoingargumentaboutwhentointroducedetailsofobject-oriented
programming. WelasttaughtJava,objectsfirst. Studentsdutifullyfollowedourlead. Later,wesawquickprograms
that students wanted to write for themselves, that were layered with totally unnecessary and distracting instances of
objects.
Wehaveseenlessproblemwiththeoppositeorder,whichweuse: startoffwithmoreproceduralprogramming,then
introducetheuseofinstancesofexistingclassesofobjects,andthenmovetodesigningclasseswithinstancevariables,
constructors,andinstancemethods,andseewheretheyaretrulyuseful. Ifyouprefer,afterthechapteronfunctions
youcanreadthefirstcoupleofsectionsinClassesandObject-OrientedProgramming,thatcoverdefiningyourown
simpleobjects.
We tend to introduce examples first, and then the general syntax, and then more examples and exercises. Later
examplesonasubjectaresometimesessentiallylinkstodocumentedcodethatisbothdirectlyvisibleontheweband
intheseparatedownloadofalloftheexamplesourcecode.
Therearereviewquestionsattheendofmostchapters. Thereviewquestionsmayseemtobeinastrangeorder:Often
we invite students to consider a general overarching theme in an early question. In case that was too much to bite
off,laterquestionsoftenexplicitlyaddressaspecificpointthatwouldhavebeenanimplicitpartofanearliergeneral
question. Sometimesalatermorepointedquestionevengivesananswertopartofanearlierquestion.
Labsareintendedasearlypracticeonasubject,withgenerallysmallbitsrequestedatatime.Theyareusuallyincluded
in the main body of the book soon after the needed background is introduced. There are also larger assignments as
someoftheappendixsections.
1.1.2 C# and Mono
Wehavetaughtintroductoryprogrammingformanyyears,throughaprogressionofprogramminglanguages. Ourlast
languagewasJava,stillthelanguageoftheAPtest,whichdrivessomanyintroductorytexts.
1
IntroductiontoComputerScienceinC#,Release1.0
WehadC#inmind: Itisamoremodernlanguage. ItsdesignersgottoreflectontheglitcheswithJava,andaddress
themeffectively.
ThekeyproblemwithC#usedtobethatitwastotallyaMicrosoftlanguageforWindows. Manyofourstudentshave
theirown machines: manyare OS-Xmachines fromApple; someare Linux. We didnot wantto cutthose students
off. NordidwewanttolimitstudentstothinkingofacomputerasaWindowsmachine. Meanwhiletheopensource
implementationofC#,Mono,hasbeenmaturing,alongwithitstoolchains.
While many open-source tools have hackers jumping in to eliminate bugs, and maybe providing enough documen-
tation for a professional, documentation for a beginner is often lacking. This book contributes there, partly in the
documentation for Mono’s lovely interactive environment csharp, and also for the integrated development environ-
ment,XamarinStudio. WeshowbeginnershowtostartusingtheXamarinStudioenvironment,withitslargearrayof
features(notallneededbythebeginner),andintroducemorefeaturesasneeded.
We aim to end up with a book that provides a solid conceptual framework for beginning computer scientists in the
context of the clean, well-established modern language, C#, using multi-platform free and open-source tools, with
cleardocumentation.
Wehopethatyoufindthistobeawinningcombination.
1.2 Resources Online
ThisbookisdesignedforComp170atLoyolaUniversity,Chicago.Thematerialsareavailabletoallontheweb.Here
aresomeimportantweblinks:
• Thecourseexamplefile, istheessentialresourcetodownloadandunzipontoyourmachine. Thezipfileand
thefolderitunzipstohavealongname,introcs-csharp-master-examples. Wesuggestyourenametheunzipped
folderexamplestomatchlaterreferences.
Computerprogramsaredesignedtorunonacomputerandsolveproblems. Thoughtheinitialproblemswillbe
tinyandoftensilly,theywillserveaslearningtoolstoprepareforsubstantiveproblems.
• http://introcs.cs.luc.edu is an online text version for your web browser. See also Downloading and Reading
Optionsforpdfandepubversions. Exceptonverygeometricallyorientedtopics,text-orientedlearnersmaybe
happiestjustreadingthebookinoneoftheseformats.
• https://luc.box.com/CSharpVideosisabox.comfoldercontainingallthevideos. Thenumbersatthebeginning
of the titles are chapter and section numbers from the text. These make it easy to sequence the videos, even
thoughthereisnotanautomaticplaylist. Thelistinginbox.comtakesupseveralpages. Thesebox.comvideos
maybe
– streamed,includingatfullsize(thoughgenerallyafteraninitialdelay),
– downloadedindividuallyor
– thewholegigabytefoldercanbedownloadedatoncetoplaylateronyourmachine. (Thisisachoiceon
themenuunderthepage’sFolderOptions.)
Thereisamixtureofnewhigh-defvideosandolderlowerresolution800x600pixelvideos. Inthatfoldersee
00README.html, https://luc.box.com/s/2lqak4pbsdcyw08ds3ia, for a description of the differences between
theoldvideosandthelatestupdateoftheonlinebook.
For those who learn best with spoken words combined with written words, the videos should be a good start.
Evenifyouuseavideoforasection,youareencouragedtoreviewthewrittentextafterward. Thenbeawareof
thewrittenversionforquickreference. Thewrittentextmayincludeextradetailsandexercises,anditwillhave
thelatestrevisions.
Invariousformats,beawareofthesehelpfulfeatures:
2 Chapter1. Context
IntroductiontoComputerScienceinC#,Release1.0
• We have picked out particularly important words, phrases, and symbols, and put them in our index, which is
accessiblefromthebannerofeachwebpage. Thebannerstaysvisibleifthewindowisbigenough,andifthe
windowissmaller,thebaneronlyappearsatthebeginningofthepagewithadropdownmenuformostofthe
options.
• Inawebversiononourwebsite,youcanusetheSearchoptiontolookforwords,ingeneral. Thesearchlinkis
alsoaccessiblefromthewebpagebanner. Thisdoesnotworkonadownloadedlocalhtmlcopy.
• The web version and pdf versions display mathematical formulas prettily. If you use the local html version
whennotconnectedtotheinternet,youseeonlytheLaTexencodedsourceforformulas. Whileofflinereading
sectionswithmathformulas,wesuggestusingthepdfversion.
• We start with a brief table of contents for the whole book. In the web versions you can get the most detailed
tableofcontentsforasinglechapterbyclickingonachaptertitleinthemaintableofcontentsorachaptertitle
intheSitedrop-downmenuinthebanner.
• Thewebversionshiftsthebehaviorofthetopbannerdependingonscreenresolution,soitadaptsforanything
fromlargemonitorstosmallmobiledevices. Withawidescreenthebannerstaysatthetopofyourscreen,and
showsallthestandardinternallinksanddrop-downmenus. Onanarrowerscreenthebannerisonlyatthetop
ofeachwebpage,andscrollsoffthescreen; theonlydirectlinkistothemaintableofcontents,whiletherest
ofthelinksofthewideversioncanbeaccessedviatheiconattherightsideofthebanner.
Herearefurtherlinksthatmaybeusefulinourrepository:
• https://github.com/LoyolaChicagoBooks/introcs-csharp/ is the home page for the repository of all the sources
forthebook. Toreadthisbook,youdonotneedtogotothatURL,butifyoudo,thehomepagegivesyouan
ideaofwhatupdateshavebeenmaderecentlytothebookoraccompanyingexamples. Sinceimprovementsare
madeonanongoingbasis,thenotesaboutrecentchangesmaybeusefultoyou.
ThemultipleproductionversionsaregeneratedlargelybySphinxsoftwarefromthecommonsetofsourcesin
therepository. Thesourcesarelargelyplaintextfiles.
• https://github.com/LoyolaChicagoBooks/introcs-csharp-examples/ is another repository containing the latest
versions of the source code files. You can quickly browse and view individual files under the Source tab.
Examplefilelinksthroughoutthistextrefertotheserepositoryfiles.
1.3 Downloading and Reading Options
MostreaderswillwanttodownloadtheC#examplesinZIPformat. Moreexperiencedreaders(withpreviousback-
ground)maypreferusingGitHub. ()
Table 1.1: ExampleSourceCodeandVideos
Description URL
C#Examples(asZIP) https://github.com/LoyolaChicagoBooks/introcs-csharp-examples/archive/master.zip
Videos https://luc.box.com/CSharpVideos
We offer the book in HTML, PDF, and EPUB formats. Kindle users should use EPUB, which can be converted to
MOBIformat. (Weplantoofferitsoonthroughourmainsite.)
1.3. DownloadingandReadingOptions 3
IntroductiontoComputerScienceinC#,Release1.0
Table 1.2: AlternateBookFormats
Format URL
WebSite http://books.cs.luc.edu/introcs-csharp/
WebSite(offlineZIP) http://books.cs.luc.edu/introcs-csharp/download/html.zip
PDF(USLetter) http://books.cs.luc.edu/introcs-csharp/download/comp170.pdf
PDF(7x9Book) http://books.cs.luc.edu/introcs-csharp/download/comp170book.pdf
EPUB(Experimental) http://books.cs.luc.edu/introcs-csharp/download/comp170.epub
Warning: Thefollowingisfordevelopersonly!
ThebooksourcecodeandexamplesareallmaintainedonGitHub. Wewelcomepullrequestsandwillacknowledge
anyhelpfulandconstructivecontributions.
Table 1.3: GitHub
Description URL
C#Examples https://github.com/LoyolaChicagoBooks/introcs-csharp-examples
BookSource https://github.com/LoyolaChicagoBooks/introcs-csharp
1.4 Computer Science, Broadly
We intend this book as an introduction to computer science, with a focus on creating problem solutions in the C#
programming language. We should not jump in too quickly. You can get lost in our details and miss an idea of the
muchlargerbreadthofcomputerscience.
1.4.1 Information Processing
ComputerScienceisthestudyandpracticeofinformationprocessing. Thiscantakemanyforms. Manyformsappear
inelectroniccomputers,butinformationprocessingtakesplaceinmanyothercontexts,too:
Intheearlydaysofelectroniccomputers,theinformationwaslargelynumerical,calculatingmathematicalfunctions.
Later analyzing textual information has become much more important, for instance: What can you tell about the
severityofthecurrentfluoutbreakbyanalyzingthephrasinginGooglesearches?
Imagesareanalyzed: Whatcanasatelliteimagetellyouaboutthedistributionofdrought?
Sounds: howdoyouconvertverbalspeechaccuratelyintowrittensentences?
DNAholdsinformationthatourbodiesprocessintoproteins.
Our brain chemicals and electronic signals process information. There is rich interplay between cognitive scientists
and computer scientists modeling problem solving in the brain with neural nets on a computer, sometimes to better
understandbrainsandsometimestobettersolveproblemsonanelectroniccomputer.
Economicsystemsarebecomingbetterunderstoodintermsoftheflowofinformation.
Thecomputer doingcomputationsandprocessingcanbeafamiliarelectroniccomputer,butitcanbegenesorbrain
chemicals,orawholesocietyasitseconomyadapts.
4 Chapter1. Context
Description:Oct 2, 2014 Introduction to Computer Science in C#. Release .. The course example file, is
the essential resource to download and unzip onto your machine. The zip . The
book has a primary site and a mirror, in case the first is down.