1. The C Player s Guide 3rd Edition Rb Whitaker pdf
download
https://ebookname.com/product/the-c-player-s-guide-3rd-edition-
rb-whitaker/
Get Instant Ebook Downloads – Browse at https://ebookname.com
2. Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...
The C Player s Guide 5th Edition Rb Whitaker
https://ebookname.com/product/the-c-player-s-guide-5th-edition-
rb-whitaker/
Complete Arcane A Player s Guide 1st Edition Richard
Baker
https://ebookname.com/product/complete-arcane-a-player-s-
guide-1st-edition-richard-baker/
The RF Transmission Systems Handbook 1st Edition Jerry
C. Whitaker (Ed.)
https://ebookname.com/product/the-rf-transmission-systems-
handbook-1st-edition-jerry-c-whitaker-ed/
Progress in Nucleic Acid Research and Molecular Biology
82 1st Edition P. Michael Conn (Eds.)
https://ebookname.com/product/progress-in-nucleic-acid-research-
and-molecular-biology-82-1st-edition-p-michael-conn-eds/
3. Chronic Inflammation Molecular Pathophysiology
Nutritional and Therapeutic Interventions 1st Edition
Sashwati Roy (Editor)
https://ebookname.com/product/chronic-inflammation-molecular-
pathophysiology-nutritional-and-therapeutic-interventions-1st-
edition-sashwati-roy-editor/
The Trainer s Handbook 2nd edition Edition Lawson K.
https://ebookname.com/product/the-trainer-s-handbook-2nd-edition-
edition-lawson-k/
Best Practice Framework for Developing and Implementing
E Government 1st Edition Abdelbaset Rabaiah
https://ebookname.com/product/best-practice-framework-for-
developing-and-implementing-e-government-1st-edition-abdelbaset-
rabaiah/
3D Make Print Second Edition Asadi Aaron.
https://ebookname.com/product/3d-make-print-second-edition-asadi-
aaron/
Artificial Intelligence for Computer Games An
Introduction 1st Edition John David Funge (Author)
https://ebookname.com/product/artificial-intelligence-for-
computer-games-an-introduction-1st-edition-john-david-funge-
author/
4. Managing Complexity of Information Systems The Value of
Simplicity 1st Edition Pirmin P. Lemberger
https://ebookname.com/product/managing-complexity-of-information-
systems-the-value-of-simplicity-1st-edition-pirmin-p-lemberger/
7. 1
Acknowledgements xvii
Introduction xix
Part 1: Getting Started
1. The C# Programming Language 3
2. Installing Visual Studio 6
3. Hello World: Your First C# Program 10
4. Comments 19
Part 2: The Basics
5. Variables 25
6. The C# Type System 31
7. Basic Math 42
8. User Input 48
9. More Math 53
10. Decision Making 60
11. Switch Statements 68
12. Looping 71
13. Arrays 77
14. Enumerations 83
15. Methods 86
16. Value and Reference Types 97
Contents at a Glance
8. Part 3: Object-Oriented Programming
17. Object-Oriented Basics 107
18. Making Your Own Classes 112
19. Properties 124
20. Tic-Tac-Toe 130
21. Structs 138
22. Inheritance 144
23. Polymorphism, Virtual Methods, and Abstract Classes 151
24. Interfaces 156
25. Using Generics 160
26. Making Generic Types 167
Part 4: Advanced Topics
27. Namespaces and Using Directives 175
28. Methods Revisited 180
29. Reading and Writing Files 190
30. Error Handling and Exceptions 194
31. Pattern Matching 201
32. Delegates 206
33. Events 212
34. Operator Overloading 219
35. Indexers 223
36. Extension Methods 226
37. Lambda Expressions 230
38. Query Expressions 236
39. Threads 245
40. Asynchronous Programming 251
41. Dynamic Objects 259
42. Unsafe Code 265
43. Other Features in C# 271
Part 5: Mastering the Tools
44. The .NET Platform 301
45. Getting the Most from Visual Studio 313
46. Dependencies and Multiple Projects 319
47. Handling Common Compiler Errors 326
48. Debugging Your Code 333
49. How Your Project Files are Organized 339
9. Part 6: Wrapping Up
50. Try It Out! 345
51. What’s Next? 351
Glossary 354
Tables and Charts 369
Index 374
10. 2
Acknowledgements xvii
Introduction xix
The Player’s Guide xix
How This Book is Organized xx
Getting the Most from This Book xxii
I Genuinely Want Your Feedback xxiii
This Book Comes with Online Content xxiii
Part 1: Getting Started
1. The C# Programming Language 3
What is C#? 3
What is the .NET Platform? 4
C# and .NET Versions 5
2. Installing Visual Studio 6
Versions of Visual Studio 7
The Installation Process 7
C# Programming on Mac and Linux 9
3. Hello World: Your First C# Program 10
Creating a New Project 10
A Brief Tour of Visual Studio 11
Building Blocks: Projects, Solutions, and Assemblies 12
Modifying Your Project 13
Compiling and Running Your Project 14
A Closer Look at Your Program 16
Contents
11. Whitespace Doesn’t Matter 17
Semicolons 18
4. Comments 19
What is a Comment? 19
Why Should I Use Comments? 19
How to Make Comments in C# 20
How to Make Good Comments 21
Part 2: The Basics
5. Variables 25
What is a Variable? 25
Creating Variables 26
Assigning Values to Variables 27
Retrieving the Contents of a Variable 27
How Data is Stored 28
Multiple Declarations and Assignments 29
Good Variable Names 29
6. The C# Type System 31
An Introduction to the Type System 31
The ‘int’ Type 31
The ‘byte’, ‘short’, and ‘long’ Types 32
The ‘sbyte’, ‘ushort’, ‘uint’, and ‘ulong’ Types 32
The ‘char’ Type 33
The ‘float’, ‘double’, and ‘decimal’ Types 34
The ‘bool’ Type 36
The ‘string’ Type 36
Numeric Literal Variations 38
Type Inference 40
7. Basic Math 42
Operations and Operators 42
Addition, Subtraction, Multiplication, and Division 43
The Remainder Operator 44
Unary ‘+’ and ‘-‘ Operators 45
Operator Precedence and Parentheses 46
Why the ‘=‘ Sign Doesn’t Mean Equals 46
Compound Assignment Operators 47
8. User Input 48
User Input from the Console 48
Converting Types 48
A Complete Sample Program 49
12. Escape Characters 51
String Interpolation 52
9. More Math 53
Integer Division 54
Working with Different Types and Casting 55
Division by Zero 56
Infinity, NaN, e, π, MinValue, and MaxValue 56
Overflow and Underflow 57
Incrementing and Decrementing 58
10. Decision Making 60
The ‘if’ Statement 61
The ‘else’ Statement 62
‘else if’ Statements 62
Curly Braces Not Always Needed 63
Relational Operators: ==, !=, <, >, <=, >= 63
Using ‘bool’ in Decision Making 65
The ‘!’ Operator 65
Conditional Operators: && and || (And and Or) 66
Nesting If Statements 66
The Conditional Operator ?: 67
11. Switch Statements 68
The Basics of Switch Statements 68
Types Allowed with Switch Statements 70
No Implicit Fall-Through 70
12. Looping 71
The While Loop 71
The Do-While Loop 73
The For Loop 73
Breaking Out of Loops 74
Continuing to the Next Iteration of the Loop 74
Nesting Loops 75
Still to Come: Foreach 76
13. Arrays 77
What is an Array? 77
Creating Arrays 78
Getting and Setting Values in Arrays 78
More Ways to Create Arrays 79
Array Length 79
Some Examples with Arrays 79
Arrays of Arrays and Multi-Dimensional Arrays 80
The ‘foreach’ Loop 81
13. 14. Enumerations 83
The Basics of Enumerations 83
Why Enumerations are Useful 85
Underlying Types 85
Assigning Numbers to Enumeration Values 85
15. Methods 86
Creating a Method 87
Calling a Method 88
Returning Stuff from a Method 89
Passing Stuff to a Method 91
Passing in Multiple Parameters 91
Method Overloading 92
Revisiting the Convert and Console Classes 94
XML Documentation Comments 94
The Minimum You Need to Know About Recursion 95
16. Value and Reference Types 97
The Stack and the Heap 97
Memory Management and Garbage Collection 98
References 99
Value Types and Reference Types 99
Null: References to Nothing 101
Value and Reference Semantics 102
Part 3: Object-Oriented Programming
17. Object-Oriented Basics 107
Object Classes and Object Instances 107
Working with an Existing Class 108
Using an Instance 109
The Power of Objects 110
Classes are Reference Types 110
18. Making Your Own Classes 112
Creating a New Class 112
Instance Variables 114
Access Modifiers: private and public 114
Constructors 115
Methods 118
The ‘static’ Keyword 120
Using Our Class 121
The ‘internal’ Access Modifier 121
Class Design and Software Engineering 122
14. 19. Properties 124
The Motivation for Properties 124
Creating Properties 125
Different Accessibility Levels 127
Auto-Implemented Properties 127
Object Initializer Syntax 128
Anonymous Types 129
20. Tic-Tac-Toe 130
Requirements 130
High-Level Design 131
Refactoring and Iterative Design 132
The Full Solution 132
21. Structs 138
Creating a Struct 138
Structs vs. Classes 139
Deciding Between a Struct and a Class 140
Prefer Immutable Value Types 141
The Built-In Types are Aliases 142
22. Inheritance 144
Base Classes 145
Derived Classes 145
Using Derived Classes 146
Constructors and Inheritance 147
The ‘protected’ Access Modifier 148
The Base Class of Everything: object 148
Sealed Classes 148
Partial Classes 149
C# Does Not Support Multiple Inheritance 150
23. Polymorphism, Virtual Methods, and Abstract Classes 151
Polymorphism 151
Revisiting the ‘base’ Keyword 153
Abstract Base Classes 154
The ‘new’ Keyword with Methods 154
24. Interfaces 156
What is an Interface? 156
Creating an Interface 157
Using Interfaces 158
Multiple Interfaces and Inheritance 159
25. Using Generics 160
The Motivation for Generics 160
What are Generics? 162
15. The List Class 162
The IEnumerable<T> Interface 164
The Dictionary Class 165
26. Making Generic Types 167
Creating Your Own Generic Types 167
Using Your Generic Type in Your Class 168
Generic Type Constraints 169
Generic Methods 171
The Default Operator 171
Part 4: Advanced Topics
27. Namespaces and Using Directives 175
Namespaces 175
Fully Qualified Names 176
Using Directives 176
The Error ‘The type or namespace X could not be found’ 176
Name Collisions 178
Static Using Directives 179
28. Methods Revisited 180
Local Functions 180
Optional Parameters 181
Named Parameters 182
Variable Number of Parameters 182
The ‘out’ and ‘ref’ Keywords 183
Returning Multiple Values 186
29. Reading and Writing Files 190
The File Class 190
Text-Based Files 192
Binary Files 193
30. Error Handling and Exceptions 194
How Exception Handling Works 195
Catching Exceptions 196
Handling Different Exceptions in Different Ways 197
Throwing Exceptions 197
The ‘finally’ Keyword 199
Exception Filters 200
Some Rules about Throwing Exceptions 200
31. Pattern Matching 201
Contrasted with Regular Expressions 201
The Pattern Concept 202
16. Available Patterns 202
Using Patterns in C# 203
Expect Patterns to Expand 205
32. Delegates 206
Delegates: Treating Methods like Objects 206
Creating a Delegate 206
Using Delegates 207
The Delegate and MulticastDelegate Classes 208
Delegate Chaining 209
The Action and Func Delegates 211
33. Events 212
Defining an Event 213
Raising an Event 214
Attaching and Detaching Event Handlers 215
Common Delegate Types Used with Events 216
The Relationship between Delegates and Events 218
34. Operator Overloading 219
Overloading Operators 220
35. Indexers 223
How to Make an Indexer 223
Using Other Types as an Index 224
Index Initializer Syntax 225
36. Extension Methods 226
Creating an Extension Method 227
37. Lambda Expressions 230
The Motivation for Lambda Expressions 230
Lambda Expressions 232
Multiple and Zero Parameters 233
Type Inference Failures and Explicit Types 233
Statement Lambdas 233
Scope in Lambda Expressions 233
Expression-Bodied Members 234
Lambdas vs. Local Functions 235
38. Query Expressions 236
From Clauses 238
Select Clauses 239
Where Clauses 239
Multiple From Clauses 239
Let Clauses 240
Join Clauses 240
Orderby Clauses 240
17. Group Clauses 241
Into Clauses 242
Group Joins 242
Query Syntax and Method Call Syntax 243
Queries are Lazy When Possible 243
39. Threads 245
Threading Code Basics 246
Using ParameterizedThreadStart 247
Thread Safety 249
40. Asynchronous Programming 251
What is Asynchronous Programming? 251
Approaches from the Early Days 252
The Task-based Asynchronous Pattern 255
The ‘async’ and ‘await’ Keywords 256
41. Dynamic Objects 259
Dynamic Type Checking 260
Dynamic Objects and the Dynamic Language Runtime 260
Emulating Dynamic Objects with Dictionaries 261
ExpandoObject 262
Extending DynamicObject 262
When to Use Dynamic Object Variations 264
42. Unsafe Code 265
Unsafe Contexts 265
Pointer Types 266
Stack Allocations 267
Fixed Statements 268
Fixed Size Arrays 269
Calling Native Code with Platform Invocation Services 270
43. Other Features in C# 271
Iterators and the Yield Keyword 272
Constants 273
Attributes 274
The ‘nameof’ Operator 275
The ‘sizeof’ Operator 276
Bit Fields 277
Reflection 280
Using Statements and the IDisposable Interface 280
Preprocessor Directives 281
Nullable Types 283
Simple Null Checks: Null Propagation Operators 283
18. Command Line Arguments 285
User-Defined Conversions 286
The Notorious ‘goto’ Keyword 287
Generic Covariance and Contravariance 290
Advanced Namespace Management 293
Checked and Unchecked Contexts 294
Volatile Fields 295
Part 5: Mastering the Tools
44. The .NET Platform 301
Overview of the .NET Platform 301
A Brief History of the .NET Platform 304
Binary, Assembly, and Compilers 304
Virtual Machines and the Common Language Runtime 306
The .NET Standard Library 308
The .NET Framework 309
.NET Core 310
Xamarin 310
App Models 311
45. Getting the Most from Visual Studio 313
Windows 313
The Options Dialog 315
Including and Excluding Files 315
Showing Line Numbers 316
IntelliSense 316
Basic Refactoring 317
Keyboard Shortcuts 317
46. Dependencies and Multiple Projects 319
Adding DLL References 320
NuGet Packages 321
Creating and Referencing Multiple Projects 323
47. Handling Common Compiler Errors 326
Understanding Compiler Errors 326
Compiler Warnings 326
Common Compiler Errors 327
General Tips for Handling Errors 331
48. Debugging Your Code 333
Launching Your Program in Debug Mode 333
Viewing Exceptions 334
Editing Your Code While Debugging 335
Breakpoints 336
19. Stepping Through Your Program 336
49. How Your Project Files are Organized 339
Visual Studio’s Projects Directory 340
The Solution Directory 340
The Project Directory 341
Part 6: Wrapping Up
50. Try It Out! 345
Message from Julius Caesar 346
Reverse It! 346
Pig Dice 347
Connect Four 347
Conway’s Game of Life 348
51. What’s Next? 351
Other Frameworks and Libraries 351
Other Topics 352
Make Some Programs 352
Where Do I Go to Get Help? 353
Parting Words 353
Glossary 354
Tables and Charts 369
Index 374
20. 4
The Player’s Guide
This book is not about playing video games. (Though programming is as fun as playing video games for
many people.) Nor is it about making video games, specifically. (Though you definitely can make video
games with C#.)
Instead, think of this book like a player’s guide, but for a programming language. A player’s guide is a
popular kind of book that is written to help game players:
learn the basics of the game,
prevent them from getting stuck,
understand how the world they’re playing in works,
learn how to overcome the obstacles and enemies they face,
point out common pitfalls they may face and locate useful items,
and master the tools they’re given.
This book accomplishes those same goals for the C# programming language. I’ll walk you through the
language from the ground up, point out places where people get stuck, provide you with hands-on
examples to explore, give you quizzes to ensure you’re on the right track, and describe how to use the
tools that you’ll need to create programs. I’ll show you the ins and outs of the many features of C#,
describing why things work the way they do, rather than just simple mechanics and syntax.
In a Nutshell
Describes the goals of this book, which is to function like a player’s guide, not a
comprehensive cover-everything-that-ever-existed book.
Breaks down how the book is organized from a high-level perspective, as well as pointing out
some of the extra “features” of the book.
Provides some ideas on how to get the most out of this book for programmers, beginners,
and anyone who is short on time.
Introduction
21. xx Introduction
My goal is to provide you with the “dungeon map” to direct you as you begin delving into C#, while still
allowing you to mostly explore whatever you want, whenever you want.
I want to point out that this book is intentionally not called Everything you Need to Know about C#, or The
Comprehensive Guide to C#. (Note that if books with those titles actually exist, I’m not referring to them
specifically, but rather, to just the general idea of an all-encompassing book.) I’m here to tell you, when
you’re done with this book, you’ll still have lots to learn about C#.
But guess what? That’s going to happen with any book you use, including those all-encompassing books.
Programming languages are complex creations, and there are enough dark corners and strange
combinations that nobody can learn everything there is to know about them. In fact, I’ve even seen the
people who designed the C# language say they just learned something new about it! For as long as you
use C#, you’ll constantly be learning new things about it, and that’s actually one of the things that makes
programming interesting.
I’ve tried to cover a lot of ground in this book, and with roughly 400 pages, anyone would expect that to
be quite a bit. And it is. But there are plenty of other books out there that are 800 or even 1200 pages
long. A book so heavy, you’ll need a packing mule to carry it anywhere. That, or permanently place it on
the central dais of an ancient library, with a single beam of dusty light shining in on it through a hole in
the marble ceiling. Instead of all that, the goal of this book is effectiveness and clarity, not
comprehensiveness. Something that will fit both on your shelf and in your brain.
It is important to point out that this book is focused on the C# programming language, rather than
libraries for building certain specific application types. So while you can build desktop applications, web
pages, and computer games with C#, we won’t be discussing WPF, ASP.NET, DirectX, or any other
platform- or framework-specific code. Instead, we’ll focus on core C# code, without bogging you down
with those additional libraries at first. Once you’ve got the hang of C#, heading into one of those areas will
be much easier.
How This Book is Organized
This book is divided into six parts. Part 1 describes what you need to get going. You’ll learn how to get set
up with the free software that you need to write code and make your first C# program.
Part 2 describes the basics of procedural programming—how to tell the computer, step-by-step, what to
do to accomplish tasks. It covers things like how information is stored (in variables), how to make
decisions, loop over things repeatedly, and put blocks of code that accomplish specific tasks into a
reusable chunk called a method. It also introduces the type system of the C# language, which is one of
the key pieces of C# programming.
Part 3 goes into object-oriented programming, introducing it from the ground up, but also getting into a
lot of the details that make it so powerful. Chapter 20, in my opinion, is the critical point of the book. By
Chapter 19, we’ve introduced all of the key concepts needed to make almost any C# program, including
classes, which is the most powerful way C# provides for building your own data types. Chapter 20
contains the task (and solution) to making a simple but complete game of Tic-Tac-Toe, which will put all of
the knowledge from the earlier chapters to the test. Everything we do after this chapter is simply fleshing
out details and giving you better tools to get specific jobs done faster.
Part 4 covers some common programming tasks, as well as covering some of the more advanced features
of C#. For the most part, these topics are independent of each other, and once you’ve made it past that
critical point in Chapter 20, you should be able to do these at any time you want.
22. How This Book is Organized xxi
Part 5 changes gears, and covers more details about Visual Studio, which you use to create C# programs,
additional information about the .NET Platform, and some tools, tricks, and information you can use as
you program.
Finally, Part 6 wraps up the book with some larger scale programs for you to try making, a chapter on
where to go next as you continue to learn C#, and a glossary of words that are defined throughout the
book, which you can use as a reference when you run across a word or phrase that you are unfamiliar
with or have forgotten about.
Try It Out!
Scattered throughout the book are a variety of sections labeled Try It Out! These sections give you simple
challenge problems and quizzes that give you a chance to play around with the new concepts in the
chapter and test your understanding. If this were a class, these would be the homework.
The purpose of these Try It Out! sections is to help you get some real world practice with the new
information. You can’t learn to drive a car by reading the owner’s manual, and you can’t learn to program
without writing any code.
I strongly encourage you to spend at least a few minutes doing each of these challenges to help you
understand what you’re reading and ensure that you’ve learned what you needed to.
If you have something else you want to explore with the new concepts instead of the challenges I’ve
provided, all the better. The only thing better than playing around with this stuff is doing something with
it that you have a personal interest in. If you want to explore a different direction, go for it!
At the end of the book, in Chapter 50, I have an entire chapter full of larger, tougher challenge problems
for you to try out. These problems involve combining concepts from many chapters together into one
program. Going through some or all of these as you’re finishing up will be a great way to make sure you’ve
learned the most important things you needed to.
The most important thing to remember about these Try It Out! sections is that the answers are all online. If
you get stuck, or just want to compare your solution to someone else’s, you can see mine at
starboundsoftware.com/books/c-sharp/try-it-out/. I should point out that just because your solution
is different from mine (or anyone else’s) doesn’t necessarily mean it is wrong. That’s one of the best parts
about programming—there’s always more than one way to do something.
In a Nutshell
At the beginning of each chapter, I summarize what it contains. These sections are designed to do the
following:
Summarize the chapter to come.
Show enough of the chapter so that an experienced programmer can know if they already know
enough to skip the chapter or if they need to study it in depth.
Review the chapter enough to ensure that you got what you needed to from the chapter. For
instance, imagine you’re about to take a test on C#. You can jump from chapter to chapter,
reading the In a Nutshell sections, and anything it describes that you didn’t already know, you can
then go into the chapter and review it.
In Depth
On occasion, there are a few topics that are not critical to your understanding of C#, but they are an
interesting topic that is related to the things you’re learning. You’ll find this information pulled out into In
Depth sections. These are never required reading, so if you’re busy, skip ahead. If you’re not too busy, I
think you’ll find this additional information interesting, and worth taking the time to read.
23. xxii Introduction
Glossary
As you go through this book, you’re going to learn a ton of new words and phrases. Especially if you’re
completely new to programming in general. At the back of this book is a glossary that contains the
definitions for these words. You can use this as a reference in case you forget what a word means, or as
you run into new concepts as you learn C#.
Getting the Most from This Book
For Programmers
If you are a programmer, particularly one who already knows a programming language that is related to
C# (C, C++, Java, Visual Basic .NET, etc.) learning C# is going to be relatively easy for you.
C# has a lot in common with all of these languages. In fact, it’s fair to say that all programming languages
affect and are inspired by other languages, because they evolve over time. C# looks and feels like a
combination of Java and C++, both of which have roots that go back to the C programming language.
Visual Basic .NET (VB.NET) on the other hand, looks and feels quite different from C# (it’s based on Visual
Basic, and Basic before that) but because both C# and VB.NET are designed and built for the .NET
Platform, they have many of the same features, and there’s almost a one-to-one correspondence between
features and keywords.
Because C# is so closely tied to these other languages, and knowing that many people may already know
something about these other languages, you’ll see me point out how C# compares to these other
languages from time to time.
If you already know a lot about programming, you’re going to be able to move quickly through this book,
especially the beginning, where you may find very few differences from languages you already know. To
speed the process along, read the In a Nutshell section at the start of the chapter. If you feel like you
already know everything it describes, it’s probably safe to skip to the next chapter.
I want to mention a couple of chapters that might be a little dangerous to skip. Chapter 6 introduces the
C# type system, including a few concepts that are key to building types throughout the book. Also,
Chapter 16 is sort of a continuation on the type system, describing value and reference types. It’s
important to understand the topics covered in those chapters. Those chapters cover some of the
fundamental ways that C# is different from these other languages, so don’t skip them.
For Busy People
One of the best parts about this book is that you don’t need to read it all. Yes, that’s right. It’s not all
mandatory reading to get started with C#. You could easily get away with only reading a part of this book,
and still understand C#. In fact, not only understand it, but be able to make just about any program you
can dream up. This is especially true if you already know a similar programming language.
At a minimum, you should start at the beginning and read through Chapter 20. That covers the basics of
programming, all the way up to and including an introduction to making your own classes. (And if you’re
already a programmer, you should be able to fly through those introductory chapters quickly.)
The rest of the book could theoretically be skipped, though if you try to use someone else’s code, you’re
probably going to be in for some surprises.
Once you’ve gone through those 20 chapters, you can then come back and read the rest of the book in
more or less any order that you want, as you have extra time.
For Beginners
If you’ve never done any programming before, be warned: learning a programming language can be hard
work. The concepts in the first 20 chapters of this book are the most important to understand. Take
24. I Genuinely Want Your Feedback xxiii
whatever time is necessary to really feel like you understand what you’re seeing in these chapters. This
gets you all of the basics, and gets you up to a point where you can make your own types using classes.
Like with the For Busy People section above, Chapter 20 is the critical point that you’ve got to get to, in
order to really understand C#. At that point, you can probably make any program that you can think of,
though the rest of the book will cover additional tools and tricks that will allow you to do this more easily
and more efficiently.
After reading through these chapters, skim through the rest of the book, so that you’re aware of what else
C# has. That’s an important step if you’re a beginner. It will familiarize you with what C# has to offer, and
when you either see it in someone else’s code or have a need for it, you’ll know exactly where to come
back to. A lot of these additional details will make the most sense when you have an actual need for it in a
program of your own creation. After a few weeks or a few months, when you’ve had a chance to make
some programs on your own, come back and go through the rest of the book in depth.
I Genuinely Want Your Feedback
Writing a book is a huge task, and no one has ever finished a huge task perfectly. There’s the possibility of
mistakes, plenty of chances to inadvertently leave you confused, or leaving out important details. I was
tempted to keep this book safe on my hard drive, and never give it out to the world, because then those
limitations wouldn’t matter. But alas, my wife wouldn’t let me follow Gandalf’s advice and “keep it secret;
keep it safe,” and so now here it is in your hands.
If you ever find any problems with this book, big or small, or if you have any suggestions for improving it,
I’d really like to know. After all, books are a lot like software, and there’s always the opportunity for future
versions that improve upon the current one. Also, if you have positive things to say about the book, I’d
love to hear about that too. There’s nothing quite like hearing that your hard work has helped somebody.
To give feedback of any kind, please visit starboundsoftware.com/books/c-sharp/feedback.
This Book Comes with Online Content
On my website, I have a small amount of additional content that you might find useful. For starters, as
people submit feedback, like I described in the last section, I will post corrections and clarifications as
needed on this book’s errata page: starboundsoftware.com/books/c-sharp/errata.
Also on my site, I will post my own answers for all of the Try It Out! sections found throughout this book. If
you get stuck, or just want something to compare your answers with, you can visit this book’s site and see
a solution. To see these answers, go to: starboundsoftware.com/books/c-sharp/try-it-out/.
The website also contains some extra problems to work on, beyond the ones contained in this book. I’ve
been frequently asked to add more problems to the book than what it currently has. Indeed, this version
contains more than any previous version. But at the same time, most people don’t actually do these
problems. To avoid drowning out the actual content with more and more problems, I’ve provided
additional problems on the website. This felt like a good compromise. These can be found at
starboundsoftware.com/books/c-sharp/additional-problems.
Additional information or resources may be found at starboundsoftware.com/books/c-sharp.
25. Part 1
Getting Started
The world of C# programming lies in front of you, waiting to be explored. In Part 1 of this book, within
just a few short chapters, we’ll do the following:
Get a quick introduction to what C# is (Chapter 1).
Get set up to start making C# programs (Chapter 2).
Write our first program (Chapter 3).
Dig into the fundamental parts of C# programming (Chapters 3 and 4).
26. 1
1The C# Programming
Language
I’m going to start off this book with a very brief introduction to C#. If you’re already a programmer, and
you’ve read the Wikipedia pages on C# and the .NET Framework, skip ahead to the next chapter.
On the other hand, if you’re new to programming in general, or you’re still a little vague on what exactly
C# or the .NET Platform is, then this is the place for you.
I should point out that we’ll get into a lot of detail about how the .NET Platform functions, and what it
gives you as a programmer in Chapter 44. This chapter just provides a quick overview of the basics.
What is C#?
Computers only understand binary: 1’s and 0’s. All of the information they keep track of is ultimately
nothing more than a glorified pile of bits. All of the instructions they run and all of the data they process
are binary.
But humans are notoriously bad at doing anything with a giant pile of 1’s and 0’s. So rather than doing
that, we created programming languages, which are based on human languages (usually English) and
structured in a way that allows you to give instructions to the computer. These instructions are called
source code, and are simple text files.
When the time is right, your source code will be handed off to a special program called a compiler, which
is able to take it and turn it into the binary 1’s and 0’s that the computer understands, typically in the form
In a Nutshell
Describes the general idea of programming, and goes into more details about why C# is a
good language.
Describes the core of what the .NET Platform is.
Gives some history on the C# programming language for context.
27. 4 Chapter 1 The C# Programming Language
of an EXE file. In this sense, you can think of the compiler as a translator from your source code to the
binary machine instructions that the computer knows.
There are thousands, maybe tens of thousands of programming languages, each good at certain things,
and less good at other things. C# is one of the most popular. C# is a simple general-purpose
programming language, meaning you can use it to create pretty much anything, including desktop
applications, server-side code for websites, and even video games.
C# provides an excellent balance between ease of use and power. There are other languages that provide
less power and are easier to use (like Java) and others that provide more power, giving up some of its
simplicity (like C++). Because of the balance it strikes, it is the perfect language for nearly everything that
you will want to do, so it’s a great language to learn, whether it’s your first or your tenth.
What is the .NET Platform?
C# relies heavily on something called the .NET Platform. It is also commonly also called the .NET
Framework, though we’ll make a subtle distinction between the two later on. The .NET Platform is a large
and powerful platform, which we’ll discuss in detail in Chapter 44. You can go read it as soon as you’re
done with this chapter, if you want.
The .NET Platform is vast, with many components, but two stand out as the most central. The first part is
the Common Language Runtime, often abbreviated as the CLR. The CLR is a software program that takes
your compiled C# code and runs it. When you launch your EXE file, the CLR will start up and begin taking
your code and translating it into the optimal binary instructions for the physical computer that it is
running on, and your code comes to life.
In this sense, the CLR is a middle-man between your code and the physical computer. This type of
program is called a virtual machine. We’ll get into more of the specifics in Chapter 44. For now, it’s only
important to know that the .NET Platform itself, specifically the CLR runtime, play a key role in running
your application—and in making it so your application can run on a wide variety of computer
architectures and operating systems.
The second major component of the .NET Platform is the .NET Standard Library. The Standard Library is
frequently called the Base Class Library. The Standard Library is a massive collection of code that you can
reuse within your own programs to accelerate the development of whatever you are working on. We will
cover some of the most important things in the Standard Library in this book, but it is huge, and deserves
a book of its own. More detail on the Standard Library and the Base Class Library can be found in Chapter
44.
Built on top of the .NET Standard Library is a collection of app models. An app model is another large
library designed for a specific type of application. This includes things like WPF and Windows Forms for
GUI applications, ASP.NET for web development, and Xamarin for iOS and Android development. Game
frameworks or engines like MonoGame and Unity could also be considered app models, though these are
not maintained directly by Microsoft.
This book, unfortunately, doesn’t cover these app models to any serious extent. There are two reasons for
this. Each app model is gigantic. You could write multiple books about each of these app models (and
indeed, there are many books out there). Trying to pack them all into this book would make it a 5000 page
book.
Second, the app models are, true to their name, specific to a certain type of application. This means that
the things that are important to somebody doing desktop development are going to be wildly different
from somebody doing web development. This book focuses on the C# language itself, and the aspects of
28. C# and .NET Versions 5
the .NET Platform that are useful to everybody. Once you’ve finished this book, you could then proceed on
to other books that focus on specific app models. (Those books all generally assume you know C#
anyway.)
We will cover how the .NET Platform is organized and how it functions in depth in Chapter 44.
C# and .NET Versions
C# has gone through quite a bit of evolution over its history. The first release was in 2002, and established
the bulk of the language features C# still has today.
A little over a year later, in 2003, C# 2.0 was released, adding in a lot of other big and powerful features,
most of which will get quite a bit of attention in this book (generics, nullable types, delegates, static
classes, etc.)
C# 3.0 expanded the language in a couple of very specific directions: LINQ and lambdas, both of which get
their own chapters in this book.
The next two releases were somewhat smaller. C# 4.0 added dynamic typing, as well as named and
optional method arguments. C# 5.0 added greatly expanded support for asynchronous programming.
In the C# 5 era, a new C# compiler was introduced: Roslyn. This compiler has a number of notable
features: it’s open source, it’s written in C# (written in the language it’s for), and it is available while your
program is running (so you can compile additional code dynamically). Something about its construction
also allows for people to more easily tweak and experiment with new features, which led to the features
added in C# 6.0 and 7.0.
C# 6.0 and 7.0 added a whole slew of little additions and tweaks across the language. While previous
updates to the language could usually be summed up in a single bullet point or two, and are given their
own chapters in this book, the new features in C# 6.0 and 7.0 are small and numerous. I try to point out
what these new features are throughout this book, so that you are aware of them.
Alongside the C# language itself, both Visual Studio and the Standard Library have both been evolving
and growing. This book has been updated to work with Visual Studio 2017 and C# 7.0 at the time of
publishing.
Future versions will, of course, arrive before long. Based on past experience, it’s a safe bet that everything
you learn in this book will still apply in future versions.
29. 2
2Installing Visual Studio
To make your own programs, people usually use a program called an Integrated Development Environment
(IDE). An IDE combines all of the tools you will commonly need to make software, including a special text
editor designed for editing source code files, a compiler, and other various tools to help you manage the
files in your project.
With C#, nearly everyone chooses to use some variation of Visual Studio, made by Microsoft. There are a
few different levels of Visual Studio, ranging from the free Community Edition, to the high-end Enterprise
Edition. In this chapter, I’ll guide you through the process of determining which one to choose.
As of the time of publication of this book, the latest version is the 2017 family. There will inevitably be
future releases, but the bulk of what’s described in this book should still largely apply in future versions.
While new features have been added over time, the fundamentals of Visual Studio have remained the
same for a very long time now.
There are three main flavors of Visual Studio 2017. Our first stop will be to look at the differences among
these, and I’ll point out one that is most likely your best choice, getting started. (It’s free, don’t worry!) I’ll
then tell you how to download Visual Studio and a little about the installation process. By the end of this
chapter, you’ll be up and running, ready to start doing some C# programming!
In a Nutshell
To program in C#, we will need a program that allows us to write C# code and run it. That
program is Microsoft Visual Studio.
A variety of versions of Visual Studio exists, including the free Community Edition, as well as
several higher tiers that offer additional features at a cost.
You do not need to spend money to make C# programs.
This chapter walks you through the various versions of Visual Studio to help you decide which
one to use, but as you are getting started, you should consider the free Visual Studio 2017
Community Edition.
31. speedy return to a home where, if the dear heart in it is still beating,
we shall meet with a sweet welcome, be sure.'
'But you must not be in a hurry to return home,' exclaimed the
Captain, turning his smiling countenance to Helga; 'you must give
me time to tempt you to remain on board The Light of the World.
Your qualifications as a sailor should make you an excellent mate,
and you will tell me how much a month you will take to serve in that
capacity?'
I observed the same look of recoil in her face that I had before seen
in it. A woman's instincts, thought I, are often amazingly keen in the
interpretation of men's minds. Or is she merely nervous and
sensitive with a gentle, pretty modesty and bashfulness which
render direct allusions to her after this pattern distressing? For my
part, I could find no more than what the French call badinage in the
Captain's speech, with nothing to render it significant outside the
bare meaning of the words in his looks or manner.
She did not answer him, and by way of changing the subject, being
also weary of sitting at that table, for we had finished the meal some
time, though the Malay continued to look on, as though waiting for
the order to clear away, I pulled out my watch.
'A quarter to seven,' I exclaimed. 'You will not wish to be late to-
night, Helga. You require a good long sleep. By this time to-morrow
we may have shifted our quarters; but we shall always gratefully
remember Captain Bunting's goodness.'
'That reminds me,' said he, 'your cabins must be got ready.
Punmeamootty, go forward and tell Nakier to send a couple of hands
aft to clear out two of the berths below. No! tell Nakier I want him,
and then come aft and clear the table.'
The man, gliding softly but moving swiftly, passed through the door
that led on to the quarter-deck.
32. 'I wish I could tempt you, Miss Nielsen,' continued the Captain, 'to
take Mr. Jones's cabin. You will be so very much more comfortable
there.'
'I would rather be near Mr. Tregarthen, thank you,' she answered.
'You are a fortunate man to be so favoured!' he exclaimed, smiling at
me. 'However, every convenience that my cabin can supply shall be
placed at Miss Nielsen's disposal. Alas! now, if my dear Judith were
here! She would improve, by many womanly suggestions, my
humble attempts as a Samaritan. Our proper business in this world,
Mr. Tregarthen, is to do good to one another. But the difficulty,' he
exclaimed with a sweep of his hand, 'is to do all the good that can
be done! Now, for instance, I am at a loss. How am I to supply Miss
Nielsen's needs?'
'They are of the simplest—are not they, Helga?' said I.
'Quite the simplest, Captain Bunting,' she answered, and then,
looking at him anxiously, she added: 'My one great desire now is to
get to England. I have been the cause of taking Mr. Tregarthen from
his mother, and I shall not feel happy until they are together again!'
'Charity forbid,' exclaimed the Captain, 'that I should question for an
instant the heroism of Mr. Tregarthen's behaviour! But,' said he,
slightly lowering his voice and stooping his smiling face at her, so to
say, 'when your brave friend put off in the lifeboat he did not, I may
take it, know that you were on board?'
'But I was on board,' she answered quickly: 'and he has saved my
life, and I wish him to return to his mother, who may believe him
drowned and be mourning him as dead!'
33. CHAPTER VII.
ON BOARD 'THE LIGHT OF THE WORLD.'
At that moment the man whom the Captain styled Nakier entered
the little cuddy, followed by the steward. He made a singular
gesture, a sort of salaam, bowing his head and whipping both hands
to his brow, but with something of defiance in the celerity of the
gesture. He was the man whom I had seen haranguing the two
boatmen. He had a large, fine intelligent eye, liquid and luminous,
despite the Asiatic duskiness of its pupil; his features were regular
and almost handsome: an aquiline nose, thin and well chiselled at
the nostrils, a square brow, small ears decorated with thick gold
hoops, and teeth as though formed of china. The expression of his
face was mild and even prepossessing, his complexion a light yellow.
He bore in his hand what had apparently been a soldier's foraging
cap, and was dressed in an old pilot jacket, a red shirt, and a pair of
canvas breeches held by a belt, to which was attached a sheath
containing a knife lying tight against his hip. He took me and Helga
in with a rapid roll of his handsome eyes, then looked straight at the
Captain in a posture of attention, with a little contraction of the
brow.
'I want a couple of the berths below cleared out at once,' said the
Captain. 'Goh Syn Koh seems one of the smartest among you. Send
him. Also send Mow Lauree. He can make a bed, I hope? He is
making a bed for himself! Bear a hand and clear this table,
Punmeamootty, so as to be able to assist. You'll superintend the
work, Nakier. See all clean and comfortable.'
'Yaas, sah,' said the man.
He was going.
34. 'Stop!' exclaimed the Captain, smiling all the time he continued to
talk. 'Did you eat your dinner to-day!'
'No, sah.'
'What has become of it?'
'Overboard, sah,' answered the man, preserving his slight frown.
'Overboard! As good a mess of pork and peasoup as was ever
served out to a ship's company. Overboard! For the third time! If it
happens again——' he checked himself with a glance at Helga: 'if it
happens again,' he went on, speaking with an air of concern, 'I shall
be obliged to stop the beef.'
'We cannot eat pork, sah—we are Mussulmans——' he was
proceeding.
The Captain silenced him with a bland motion of the hand.
'Send the men aft, Nakier,' said he, with a small increase of nasal
twang in his utterance, 'and see that the cleaning and the clearance
out is thorough.'
He gave him a hard, significant nod, and the man marched out,
directing an eager look at me as he wheeled round, as though for
my sympathy.
Punmeamootty was clearing the table with much ill-dissembled
agitation in the hurry of his movements: his swift glances went from
the Captain to me, and then to Helga. They were like the flashing of
a stiletto, keen as the darting blue gleam of the blade, and they
would be as murderous, too, I thought, if the man could execute his
wishes with his eyes. I believed the Captain would now make some
signal to leave the table, but he continued to sit on.
'Did you observe that man just now?' said he, addressing Helga. She
answered 'Yes.' 'Handsome, do you think?' said he.
'He had a mild, pleasant face,' she answered.
35. 'His name,' said he, 'is Vanjoor Nakier. He is boss of the native crew,
and I allow him to act as a sort of boatswain. It is hard to reconcile
so agreeable a countenance with the horrible and awful belief which
must make him for ever and ever a lost soul, if he is not won over in
plenty of time for repentance, for prayer and mortification.'
'You seem to have the fellows' names very pat,' said I. 'Are you
acquainted with the Malay tongue?'
'Ah!' cried he, with a shake of the head; 'I wish I were. I might then
prove a true missionary to the poor benighted fellows. Yet I shall
hope to have broken heavily into their deplorable and degraded
superstitions before I dismiss them at Cape Town.'
I caught sight of the shadowy form of the steward lurking abaft the
companion-steps, where he seemed busy with some plates and a
basket.
'It is your hope,' said I, 'to convert the Mussulmans?'
'It is my hope, indeed,' he answered; 'and, pray, what honester hope
should possess a man?'
'It is an admirable desire,' said I, 'but a little dangerous perhaps.'
'Why?' asked he.
'Well,' said I, 'I am no traveller. I have seen nothing of the world, but
I have read, and I have always gathered from books of voyages,
that there is no class of men more bigoted in their faith and more
treacherous in their conduct than Malay seamen.'
'Hush!' cried Helga, putting her finger to her lips and looking in the
direction of the steward.
The Captain turned in his chair.
'Are you there, Punmeamootty?'
'Yes, sah;' and his figure came swiftly gliding into the light.
36. 'Go below and help the others! They should be at work by this time.'
The man went out on to the quarter-deck, where, close against the
cuddy front, lay the little hatch that conducted to the steerage.
'You are quite right,' exclaimed the Captain, lying back and
expanding his waistcoat. 'Malay seamen are, undoubtedly,
treacherous. In fact, treachery is part and parcel of the Malay
character. It is the people of that nation who run amuck, you know.'
'What is that?' inquired Helga.
'A fellow falls crazy,' answered the Captain, smiling, 'whips out a
weapon called a creese, and stabs and kills as many as he can
encounter as he flies through the streets.'
'They are a people to live on good terms with,' said Helga, looking at
me.
'They are a people,' said the Captain, nasally accentuating his words,
'who are to be brought to a knowledge of the Light; and, in
proportion as the effort is dangerous, so should the worker glory in
his task.'
He gazed at Helga, as though seeking her approval of this
sentiment. But she was looking at me with an expression of anxiety
in her blue eyes.
'I gather,' said I, with curiosity stimulated by thought of the girl's and
my situation aboard this homely little barque, with her singular
skipper and wild, dark crew—'I gather, Captain Bunting, from what
has passed, that the blow you are now levelling at these fellows'
superstitions—as you call them—is aimed at their diet?'
'Just so,' he answered. 'I am trying to compel them to eat pork. Who
knows that before the equator be crossed I may not have excited a
real love for pork among them? That would be a great work, sir. It
will sap one of the most contemptible of their superstitions, and
37. provide me with a little crevice for the insertion of the wedge of
truth.'
'I believe pork,' said I, 'is not so much a question of religion as a
question of health with these poor dark creatures, bred in hot
latitudes.'
'Pork enters largely into their faith,' he answered.
'So far, you have not been very successful, I think?'
'No. You heard what Vanjoor Nakier said. The wasteful wretches
have for the third time cast their allowance overboard. Only think,
Miss Nielsen, of wilfully throwing over the rail as much hearty
excellent food—honest salt pork and very fair peasoup—as would
keep a poor family at home in dinners for a week!'
'What do they eat instead?' she asked.
'Why, on pork days, biscuit, I suppose. There is nothing else.'
'You give them beef every other day?' said I.
'Beef and duff,' he answered; 'but I shall stop that. Famine may help
me in dealing with their superstitions.'
It was not for me, partaking, as Helga and I were, of this man's
hospitality, using his ship, dependent upon him, indeed, for my
speedy return home with Helga—it was not for me, I say, at this
early time at all events, to remonstrate with him, to tell him that,
exalted as he might consider his motives, they were urging him into
a very barbarous, cruel behaviour; but, as I sat looking at him, my
emotion, spite of his claims upon my kindness, was one of hearty
disgust, with deeper feelings working in me besides, when I
considered that, if our evil fortune forced us to remain for any length
of time on board The Light of the World, we might find his theory of
conversion making his ship a theatre for as bad a tragedy as was
ever enacted upon the high seas.
38. On a sudden he looked up at a little timepiece that was ticking
against a beam just over his head.
'Have you any acquaintance with the sea, Mr. Tregarthen?' he asked.
'Merely a boating acquaintance,' I replied.
'Can you stand a watch?'
'I could keep a look-out,' said I, a little dismayed by these questions,
'but I am utterly ignorant of the handling of a ship.'
He looked reflectively at Helga, then at me, pulling down first one
whisker, then the other, while his thick lips lay broad in a smile under
his long hooked nose.
'Oh, well' said he, 'Abraham Wise will do.' He went to the cuddy door
and called 'Forward there!'
'Yaas, sah,' came a thick Africander-like note out of the forecastle
obscurity.
'Ask Abraham Wise to step aft.'
He resumed his seat, and in a few minutes Abraham arrived. Helga
instantly rose and gave him her hand with a sweet cordial smile that
was full of her gratification at the sight of him. For my part, it did my
heart good to see him. After the tallowy countenance and odd talk
of the Captain and the primrose complexions and scowling glances
of his Malays, there was real refreshment to the spirits to be got out
of the homely English face and English 'longshore garb of the
boatman, with the man's suggestions, besides, of the English
Channel and of home.
'And how is Jacob?' said I.
'Oh, he's a-feeling a little better, sir. A good bit down, of course, as
we both are. 'Taint realizable even now.'
'Do you refer to the loss of your lugger?' said Captain Bunting.
39. 'Ay, sir, to the Airly Marn,' answered Abraham, confronting him, and
gazing at him with a steadfastness that slightly increased his squint.
'But surely, my good fellow,' cried the Captain, 'you had plenty of
time, I hope, to feel thoroughly grateful for your preservation from
the dreadful fate which lay before you had Providence suffered you
to continue your voyage?'
'Oi dunno about dreadful fate,' answered Abraham: 'all I can say is, I
should be blooming glad if that there Airly Marn was afloat again, or
if so be as we'd never fallen in with this here Light of the World.'
'It is as I told you, you perceive,' exclaimed the Captain, smiling and
addressing Helga and me in his blandest manner: 'as we descend
the social scale, recognition of signal and providential mercies grows
feebler and feebler, until it dies out—possibly before it gets down to
Deal boatmen. I want a word with you, Abraham Wise. But first,
how have you been treated forward?'
'Oh, werry well indeed, sir,' he answered. 'The mate showed us
where to tarn in when the time comes round, and I dessay we'll
manage to git along all right till we gets clear of ye.'
'What have you had to eat?'
'The mate gave us a little bit o' pork for to be biled, but ye've got a
black cook forrads as seemed to Jacob and me to take the dressing
of that there meat werry ill.'
The Captain seemed to motion the matter aside with his hand, and
said:
'My vessel is without a second mate; I mean, a man qualified to take
charge of the deck when Mr. Jones and I are below. Now, I am
thinking that you would do very well for that post.'
'I'd rather go home, sir,' said Abraham.
40. 'Ay,' said the Captain, complacently surveying him, 'but while you are
with me, you know, you must be prepared to do your bit. I find
happiness in assisting a suffering man. But,' added he nasally, 'in
this world we must give and take. You eat my meat and sleep in
what I think I may fairly term my bedroom. What pay do I exact?
Simply the use of your eyes and limbs.'
He glanced with a very self-satisfied expression at Helga. It seemed,
indeed, that most of his talk now was at her when not directly to
her. She had come round to my side of the table after leaving
Abraham, and giving her my chair, I stood listening, with my hand
on the back of it.
'I'm quite willing to tarn to,' said Abraham, 'while I'm along with ye,
sir. I ain't afeared of work. I dorn't want no man's grub nor shelter
for nothen.'
'Quite right,' said the Captain; 'those are respectable sentiments. Of
course, if you accept my offer I will pay you, give you the wages
that Winstanley had—four pounds a month for the round voyage.'
Abraham scratched the back of his head and looked at me. This
proposal evidently put a new complexion upon the matter to his
mind.
'You can handle a ship, I presume?' continued the Captain.
'Whoy, yes,' answered Abraham with a grin of wonder at the
question: 'if I ain't been poiloting long enough to know that sort o'
work, ye shall call me a Malay.'
'I should not require a knowledge of navigation in you,' said the
Captain.
Abraham responded with a bob of the head, then scratching at his
back hair afresh, said:
'I must ask leave to tarn the matter over. I should like to talk with
my mate along o' this.'
41. 'I'll put him on the articles, too, if he likes, at the current wages,'
said the Captain. 'However, think over it. You can let me know to-
morrow. But I shall expect you to take charge during the middle
watch.'
'That I'll willingly dew, sir,' answered Abraham. 'But how about them
Ceylon chaps and Malays forrads? Dew they understand sea tarms?'
'Perfectly well,' answered the Captain, 'or how should I and Mr.
Jones get along, think you?'
'Well,' exclaimed Abraham: 'I han't had much to say to 'em as yet.
One chap's been talking a good deal this evening, and I allow he's
got a grievance, as most sailors has. There's some sort o' difficulty: I
allow it lies in the eating; but a man wants practice to follow noicely
what them there sort o' coloured covies has to say.'
'Well,' exclaimed the Captain, with another bland wave of the hand
in dismissal of the subject, 'we understand each other, at all events,
my lad.'
He went to the locker from which he had extracted the biscuits,
produced a bottle of rum, and filled a wineglass.
'Neat or with water?' said he, smiling.
'I've pretty nigh had enough water for to-day, sir,' answered
Abraham, grinning too, and looking very well pleased at this act of
attention. 'Here's to you, sir, I'm sure, and wishing you a prosperous
woyage. Mr. Tregarthen, your health, sir, and yourn, miss, and may
ye both soon get home and find everything comfortable and roight.'
He drained the glass with a smack of his lips. 'As pretty a little drop
o' rum as I've had this many a day,' said he.
'You can tell Jacob to lay aft presently,' said the Captain, 'when the
steward is at liberty, and he will give him such another dose. That
will do.'
42. Abraham knuckled his forehead, pausing to say to me in a hoarse
whisper, which must have been perfectly audible to the Captain. 'A
noice gemman, and no mistake.'
'I am going below,' said the Captain when he was gone, 'to see after
your accommodation. Will you sit here,' addressing Helga, 'or will
you go on deck for a few turns? I fear you will find the air chilly.'
'I will go on deck with you, Hugh,' answered Helga.
The Captain ran his eye over her.
'You are without luggage,' said he, 'and, alas! wanting in almost
everything; but if you will allow me——' he broke off and went to his
cabin, and before we could have found time to exchange a whisper,
returned with a very handsome, almost new, fur coat.
'Now, Miss Nielsen,' said he, 'you will allow me to wrap you in this.'
'Indeed my jacket will keep me warm,' she answered, with that
same look of shrinking in her face I have before described.
'Nay, but wear it, Helga,' said I, anxious to meet the man, at all
events, halfway in his kindness. 'It is a delightful coat—the very
thing for the keen wind that is blowing on deck!'
Had I offered to put it on for her she would at once have consented,
but I could observe the recoil in her from the garment stretched in
the Captain's hands, with his pale fat face smiling betwixt his long
whiskers over the top of it. On a sudden, however, she turned and
suffered him to put the coat on her, which he did with great
ostentation of anxiety and a vast deal of smiling, and, as I could not
help perceiving, with a deal more of lingering over the act than there
was the least occasion for.
'Wonderfully becoming, indeed!' he exclaimed; 'and now to see that
your cabin is comfortable.'
He passed through the door, and we mounted the companion steps.
43. The night was so dark that there was very little of the vessel to be
seen. Her dim spaces of canvas made a mere pale whistling shadow
of her as they floated, waving and bowing, in dim heaps through the
obscurity. There was a frequent glancing of white water to windward
and a dampness as of spray in the wind, but the little barque tossed
with dry decks over the brisk Atlantic heave, crushing the water off
either bow into a dull light of seething, against which, when she
stooped her head, the round of the forecastle showed like a segment
of the shadow in a partial eclipse of the moon. The haze of the
cabin-lamp lay about the skylight, and the figure of the mate
appeared in and vanished past it with monotonous regularity as he
paced the short poop. There was a haze of light, too, about the
binnacle-stand, with a sort of elusive stealing into it of the outline of
the man at the helm. Forward the vessel lay in blackness. It was
blowing what sailors call a top-gallant breeze, with, perhaps, more
weight in it even than that; but the squabness of this Light of the
World promised great stiffness, and, though the wind had drawn
some point or so forward while we were at table, the barque rose as
stiff to it as though she had been under reefed topsails.
'Will you take my arm, Helga?' said I.
'Let me first turn up the sleeves of this coat,' said she.
I helped her to do this; she then put her hand under my arm, and
we started to walk the lee-side of the deck as briskly as the swing of
the planks would suffer. Scarcely were we in motion when the mate
came down to us from the weather-side.
'Beg pardon,' said he. 'Won't you and the lady walk to wind'ard?'
'Oh, we shall be in your way!' I answered. 'It is a cold wind.'
'It is, sir.'
'But it promises a fair night,' said I.
'I hope so,' he exclaimed. 'Dirty weather don't agree with dirty skins.'
44. He turned on his heel and resumed his post on the weather-side of
the deck.
'Dirty skins mean Malays in that chief mate's nautical dictionary,' said
I.
'Hugh, how thankful I shall be when we are transferred to another
ship!'
'Ay, indeed! but surely this is better than the lugger?'
'No! I would rather be in the lugger.'
'How now?' cried I. 'We are very well treated here. Surely the
Captain has been all hospitality. No warm-hearted host ashore could
do more. Why, here is he now at this moment superintending the
arrangement of our cabins below to ensure our comfort!'
'I do not like him at all!' said she, in a tone which her slightly Danish
accent rendered emphatic.
'I do not like his treatment of the men,' said I; 'but he is kind to us.'
'There is an unwholesome mind in his flabby face!' she exclaimed.
I could not forbear a laugh at this strong language in the little
creature.
'And then his religion!' she continued. 'Does a truly pious nature talk
as he does? I can understand professional religionists intruding their
calling upon strangers; but I have always found sincerity in matters
of opinion modest and reserved—I mean among what you call
laymen. What right has this man to force upon those poor fellows
forward the food that they are forbidden by their faith to eat?'
'Yes,' said I; 'that is a vile side of the man's nature, I must own; vile
to you and me and to the poor Malays, I mean. But, surely, there
must be sincerity too, or why should he bother himself?'
45. 'It may be meanness,' said she: 'he wants to save his beef;
meanness and that love of tyrannizing which is oftener to be found
among the captains of your nation, Hugh, than mine!'
'Your nation!' said I, laughing. 'I claim you for Great Britain by virtue
of your English speech. No pure Dane could talk your mother's
tongue as you do. Spite of what you say, though, I believe the man
sincere. Would he, situated as he is—two white men to eleven
yellow-skins (for we and the boatmen must count ourselves out of it)
—would he, I say, dare venture to arouse the passions—the religious
passions—of a set of men who hail from the most treacherous
community of people in the world, if he were not governed by some
dream of converting them?—a fancy that were you to transplant it
ashore, would be reckoned noble and of a Scriptural and martyr-like
greatness.'
'That may be,' she answered; 'but he is going very wickedly to work,
nevertheless, and it will not be his fault if those coloured sailors do
not dangerously mutiny long before he shall have persuaded the
most timid and doubting of them that pork is good to eat.'
'Yes,' said I gravely; for she spoke with a sort of impassioned
seriousness that must have influenced me, even if I had not been of
her mind. 'I, for one, should certainly fear the worst if he persists—
and I don't doubt he will persist, if Abraham and the other boatman
agree to remain with him; for then it will be four to eleven—
desperate odds, indeed, though as an Englishman he is bound to
underrate the formidableness of anything coloured. However,' said I,
with a glance into the darkness over the side, 'do not doubt that we
shall be transhipped long before any trouble happens. I shall
endeavour to have a talk with Abraham before he decides. What he
and Jacob then do, they will do with their eyes open.'
As I spoke these words, the Captain came up the ladder and
approached us.
46. 'Ha! Miss Nielsen,' he cried, 'were not you wise to put on that warm
coat? All is ready below; but still let me hope that you will change
your mind and occupy Mr. Jones's berth.'
'Thank you; for the short time we shall remain in this ship the cabin
you have been good enough to prepare will be all I require,' she
answered.
He peered through the skylight to see the hour.
'Five minutes to eight,' he exclaimed. 'Mr. Jones!' The man crossed
the deck. 'I have arranged,' said the Captain, 'with the Deal boatman
Abraham Wise to take charge of the barque during the middle
watch. It is an experiment, and I shall require to be up and down
during those hours to make sure of him. Not that I distrust his
capacities. Oh dear no! From the vicious slipping of cables, merely
for sordid purposes of hovelling, to the noble art of navigating a ship
in a hurricane amid the shoals of the Straits of Dover, your Deal
boatman is the most expert of men. But,' continued he, 'since I shall
have to be up and down, as I have said, during the middle watch, I
will ask you to keep charge of the deck till midnight.'
'Very good, sir,' said the mate, who appeared to me to have been on
duty ever since the hour of our coming aboard. 'It will keep the
round of the watches steady, sir. The port watch comes on duty at
eight bells.'
'Excellent!' exclaimed the Captain. 'Thank you, Mr. Jones.'
The mate stalked aft.
'Mr. Tregarthen,' he added, 'I observe that you wear a sou'-wester.'
'It is the headgear I wore when I put off in the lifeboat,' said I, 'and
I am waiting to get home to exchange it.'
'No need, no need!' cried he; 'I have an excellent wideawake below
—not, indeed, perfectly new, but a very serviceable clinging article
for ocean use—which is entirely at your service.'
47. 'You are all kindness!'
'Nay,' he exclaimed in a voice of devotion, 'I believe I know my duty.
Shall we linger here, Miss Nielsen, or would you prefer the shelter of
the cabin? At half-past eight Punmeamootty will place some hot
water, biscuit, and a little spirit upon the table. I fear I shall be at a
loss to divert you.'
'Indeed not!' exclaimed Helga.
The unconscious irony of this response must have disconcerted a
less self-complacent man.
'I have a few volumes of an edifying kind, and a draughtboard. My
resources for amusing you, I fear, are limited to those things.'
The sweep of the wind was bleaker than either of us had imagined,
and, now that the Captain had joined us, the deck possessed no
temptation. We followed him into the cabin, where Helga hastily
removed the coat as though fearing the Captain would help her. His
first act was to produce the wideawake he had spoken of. This was a
very great convenience to me; the sou'-wester lay hot and heavy
upon my head, and the sense of its extreme unsightliness added not
a little to the discomfort it caused me. He looked at my sea-boots
and then at his feet, and, with his head on one side, exclaimed, in
his most smiling manner, that he feared his shoes would prove too
large for me, but that I was very welcome to the use of a pair of his
slippers. These also I gratefully accepted, and withdrew to Mr.
Jones's berth to put them on, and the comfort of being thus shod,
after days of the weight and unwieldiness of my sea-boots, it would
be impossible to express.
'I think we shall be able to make ourselves happy yet,' said the
Captain. 'Pray sit, Miss Nielsen. Do you smoke, Mr. Tregarthen?'
'I do, indeed,' I answered, 'whenever I can get the chance.'
He looked at Helga, who said to me: 'Pray smoke here, Hugh, if the
Captain does not object. My father seldom had a pipe out of his
48. mouth, and I was constantly in his cabin with him.'
'You are truly obliging,' said the Captain; and going to the locker in
which he kept his rum, biscuits, and the like, he took out a cigar-
box, and handed me as well-flavoured a Havannah as ever I had
smoked in my life. All this kindness and hospitality was, indeed,
overwhelming, and I returned some very lively thanks, to which he
listened with a smile, afterwards, as his custom was, waving them
aside with his hand. He next entered his cabin and returned with
some half-dozen books, which he put before Helga. I leaned over
her shoulder to look at them, and speedily recognised 'The Whole
Duty of Man,' 'The Pilgrim's Progress,' Young's 'Night Thoughts,' a
volume by Jeremy Taylor; and the rest were of this sort of literature.
Helga opened a volume and seemed to read. When I turned to ask
the Captain a question about these books, I found him staring at her
profile out of the corner of his eyes, while with his right hand he
stroked his whisker meditatively.
'These are all very good books,' said I, 'particularly the "Pilgrim's
Progress."'
'Yes,' he answered with a sigh; 'works of that kind during my long
periods of loneliness upon the high seas are my only solace, and
lonely I am. All ship-captains are more or less alone when engaged
in their profession, but I am peculiarly so.'
'I should have thought the Church, Captain, would have suited you
better than the sea,' said I.
'Not the Church,' he answered. 'I am a Nonconformist, and Dissent is
stamped upon a long pedigree. Pray light up, Mr. Tregarthen.'
He took his seat at the head of the table, put a match to his cigar,
the sight of which betwixt his thick lips considerably humanized him
in my opinion, and, clasping his pale, gouty-looking hands upon the
table, leaned forward, furtively eyeing Helga over the top of his
cigar, which forked up out of his mouth like the bowsprit of a ship.
49. His conversation chiefly concerned himself, his past career, his
antecedents, and so forth. He talked as one who wishes to stand
well with his hearers. He spoke of a Lady Duckett as a connection of
his on his mother's side, and I observed that he paused on
pronouncing the name. He told us that his mother had come from a
very ancient family that had been for centuries established in
Cumberland, but he was reticent on the subject of his father. He
talked much of his daughter's loneliness at home, and said he
grieved that she was without a companion—someone who would be
equally dear to them both; and as he said this he lay back in his
chair in a very amplitude of waistcoat, with his eyes fixed on the
upper deck and his whole posture suggestive of pensive thought.
Well, thought I, this, to be sure, is a very strange sort of sea-
captain. I had met various skippers in my day, but none like this
man. Even a trifling expletive would have been refreshing in his
mouth. From time to time Helga glanced at him, but with an air of
aversion that was not to be concealed from me, however self-
complacency might blind him to it. She suddenly exclaimed, with
almost startling inconsequentiality:
'You will be greatly obliging us, Captain Bunting, by giving orders to
Mr. Jones or to Abraham to keep a look-out for ships sailing north
during the night. We can never tell what passing vessel might not be
willing to receive Mr. Tregarthen and me.'
'What! In the darkness of night?' he exclaimed. 'How should we
signal? How would you have me convey my desire to communicate?'
'By a blue light, or by burning a portfire,' said Helga shortly.
'Ah, I see you are a thorough sailor—you are not to be instructed,'
he cried, jocosely wagging his whiskers at her. 'Think of a young lady
being acquainted with the secret of night communications at sea! I
fear—I fear we shall have to wait for the daylight. But what,' he
exclaimed unctuously, 'is the reason of this exceeding desire to
return home?'
50. 'Oh, Captain,' said I, 'home is home.'
'And Mr. Tregarthen wishes to return to his mother,' said Helga.
'But, my dear young lady, your home is not in England, is it?' he
asked.
She coloured, faltered, and then answered: 'My home is in
Denmark.'
'You have lost your poor dear father,' said he, 'and I think I
understood you to say, Mr. Tregarthen, that Miss Nielsen's poor dear
mother fell asleep some years since.'
This was a guess on his part. I had no recollection whatever of
having told him anything of the sort.
'I am an orphan,' exclaimed Helga, with a little hint of tears in her
eyes, 'and—and, Captain Bunting, Mr. Tregarthen and I want to
return home.'
'Captain Bunting will see to that, Helga,' said I, conceiving her
somewhat too importunate in this direction.
She answered me with a singularly wistful, anxious look.
The conversation came to a pause through the entrance of
Punmeamootty. He arrived with a tray and hot water, which he
placed upon the table together with some glasses. The Captain
produced wine and a bottle of rum. Helga would take nothing,
though no one could have been more hospitably pressing than
Captain Bunting. For my part, I was glad to fill my glass, as much for
the sake of the tonic of the spirit as for the desire to appear entirely
sociable with this strange skipper.
'You can go forward,' he exclaimed to the Malay; and the fellow
went gliding on serpentine legs, as it veritably seemed to me, out
through the door.
51. No further reference was made to the subject of our leaving the
barque. The Captain was giving us his experiences of the Deal
boatmen, and relating an instance of heroic roguery on the part of
the crew of a galley-punt, when a noise of thick, throaty, African-like
yowling was heard sounding from somewhere forward, accompanied
by one or two calls from the mate overhead.
'I expect Mr. Jones is taking in the foretop-gallant sail,' said the
Captain. 'Can it be necessary? I will return shortly.' And, giving Helga
a convulsive bow, he pulled his wideawake to his ears and went on
deck.
'You look at me, Hugh,' said Helga, fixing her artless, sweet, and
modest eyes upon me, 'when I speak to Captain Bunting as though I
do wrong.'
I answered gently, 'No. But is it not a little ungracious, Helga, to
keep on expressing your anxiety to get away, in the face of all this
hospitable treatment and kindly anxiety to make us comfortable and
happy while we remain?'
She looked somewhat abashed. 'I wish he was not so kind,' she said.
'What is your misgiving?' said I, inclining towards her to catch a
better view of her face.
'I fear he will not make haste to tranship us,' she answered.
'But why should he want to keep us?'
She glanced at me with an instant's surprise emphasized by a brief
parting of her lips that was yet not a smile. She made no answer,
however.
'He will not want to keep us,' continued I, talking with the
confidence of a young man to a girl whom he is protecting, and
whose behaviour assures him that she looks up to him and values
his judgment. 'We may prove very good company for a day or two,
but the master of a vessel of this sort is a man who counts his
52. Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!
ebookname.com