Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Full download Code Like a Pro in C MEAP V05 Jort Rodenburg pdf docx

Download as pdf or txt
Download as pdf or txt
You are on page 1of 55

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Code Like a Pro in C MEAP V05 Jort Rodenburg

https://textbookfull.com/product/code-like-a-pro-in-c-
meap-v05-jort-rodenburg/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Code Like a Pro in Rust 1st Edition Brenden Matthews

https://textbookfull.com/product/code-like-a-pro-in-rust-1st-edition-
brenden-matthews/

textboxfull.com

Kubernetes in Action, Second Edition (MEAP V05) Marko


Luksa

https://textbookfull.com/product/kubernetes-in-action-second-edition-
meap-v05-marko-luksa/

textboxfull.com

Get Programming with Scala MEAP V05 Daniela Sfregola

https://textbookfull.com/product/get-programming-with-scala-
meap-v05-daniela-sfregola/

textboxfull.com

Get Programming with Scala MEAP V05 Daniela Sfregola

https://textbookfull.com/product/get-programming-with-scala-
meap-v05-daniela-sfregola-2/

textboxfull.com
Testing JavaScript Applications MEAP V05 Lucas Da Costa

https://textbookfull.com/product/testing-javascript-applications-
meap-v05-lucas-da-costa/

textboxfull.com

Five Lines of Code MEAP V04 Christian Clausen

https://textbookfull.com/product/five-lines-of-code-
meap-v04-christian-clausen/

textboxfull.com

How To Build a Sauna Building Your Own Cheap Indoor Sauna


From Scratch Like a Pro Victor Allan

https://textbookfull.com/product/how-to-build-a-sauna-building-your-
own-cheap-indoor-sauna-from-scratch-like-a-pro-victor-allan/

textboxfull.com

Functional Programming in C#: How to write better C# code


1st Edition Enrico Buonanno

https://textbookfull.com/product/functional-programming-in-c-how-to-
write-better-c-code-1st-edition-enrico-buonanno/

textboxfull.com

How to Be a Coder Learn to Think Like a Coder with Fun


Activities Then Code in Scratch 3 0 Online 1st Edition
Kiki Prottsman
https://textbookfull.com/product/how-to-be-a-coder-learn-to-think-
like-a-coder-with-fun-activities-then-code-in-scratch-3-0-online-1st-
edition-kiki-prottsman/
textboxfull.com
MEAP Edition
Manning Early Access Program
Code like a Pro in C#
Version 5

Copyright 2020 Manning Publications

For more information on this and other Manning titles go to


manning.com

©Manning Publications Co. To comment go to liveBook


welcome
Dear Reader,

Thank you for purchasing the MEAP for Code Like a Pro in C#. I wrote this book for people with
previous experience in object-oriented programming to teach them the ways of writing
amazing C# code. It doesn’t matter whether your experience is in C#, Java, Kotlin, or any
other language. With this book’s focus on how to write clean, readable, idiomatic C# code, you
won’t find granular descriptions of what a for-loop or a variable is. Instead, you’ll find practical
techniques and concepts that can elevate your code and impress your peers.
The first time I encountered C# and .NET was when I was hired by a Microsoft shop.
Previously, I worked in Java, a language I found simultaneously easy to understand yet wonky
in some of its design decisions. (There were also bleak periods of work in Python and Delphi,
but I don’t publicly admit to that.) To hit the ground running at my new job, I had to get up to
speed quickly, so I couldn’t afford to start with a book along the lines of “Learn Programming
through C#” or “Programming 101.” At the end of day one, I was versed in the syntax of C#
and could cobble together some unit tests against the existing codebase. Two weeks later, I
had forced my way through some beginner and advanced resources, not knowing how to fill my
knowledge gaps or sometimes not even aware that I had them. If I had had this book when I
was switching to C#, my journey would have been a lot easier.
Throughout this book, you follow a fictitious airline in its struggle to update their codebase.
You learn how to rewrite legacy code and how to make it conform to clean code principles and
security concepts, and how to make readability improvements. I hope this book can serve you
in your development journey. If you have been writing C# for many years and want to elevate
your skill level: welcome. If you were told by your manager that you need to “pick up C# by
the afternoon”: also welcome and I’m sorry.
In closing, I ask you to do me one favor. It’s a small one, I promise. If you find something
that is exceptionally boring, not explained very well, or simply wrong: please let me know in
the book’s forum.

Thank you,

Jort Rodenburg

©Manning Publications Co. To comment go to liveBook


brief contents
PART 1: USING C# AND .NET
1 Introducing C# and .NET
2 Tour de C# and .NET
PART 2: INHERITING CODE
3 Requirements, models, and views
4 Examining the controller class
PART 3: THE DATABASE ACCESS LAYER

5 Setting up a project and database with Entity Framework Core


PART 4: THE REPOSITORY LAYER

6 Test-Driven Development and dependency injection


7 Equality, nullable types, and operator overloading
8 Stubbing, generics, and coupling
9 Extension methods, streams, and abstract classes
PART 5: THE SERVICE LAYER

10 Reflection and mocks


11 Runtime type checking revisited and error handling
12 Using IAsyncEnumerable<T> and yield return
PART 6: THE CONTROLLER LAYER

13 Middleware, HTTP routing, and HTTP responses


14 JSON serialization /deserialization and custom model binding

©Manning Publications Co. To comment go to liveBook


PART 7: CODING KATAS
15 Coding kata: The “Welcome Aboard-a-Tron 3000”
16 Coding kata: “Adjacency Matrix”
APPENDIXES
A Exercise answers
B Clean code checklist
C Installation guides
D OpenAPI FlyTomorrow
E Reading list

©Manning Publications Co. To comment go to liveBook


1

Part One

In this first part of the book, we take a brief tour of the C# language and talk about some of
its unique features. Chapter 1 covers what C# and .NET are and why you would (and would
not) use them for your projects. Chapter 2 looks at some of the features that the .NET
Framework offers us that are not always present in other platforms. We also take a C#
method based on the Pythagorean Theorem through C#’s compilation process, stopping at
each major step along the way.
This part is truly the introduction of this book but it still provides invaluable information
to somebody familiar with C#. Some of the knowledge introduced in these first two chapters
are things you need to know before moving onto more advanced resources.

©Manning Publications Co. To comment go to liveBook


2

Introducing C# and .NET

This chapter covers

• What C# and .NET are


• Why you would use C# for your projects (and why you wouldn’t)
• Switching to C#
• What this book teaches
Another book on C#, you say? Yes, another one. Plenty of books are written about C# and
.NET, but this book has one fundamental difference: I wrote this book to help you develop
clean, idiomatic C# code in your day-to-day life. This book is not a reference book but rather
a practical guide. This book does not cover things like “How to write an if statement”, “what
is a method signature”, or “what is an object”. We are not very concerned about syntax but
instead focus on concepts and ideas. There is a difference between knowing the syntax of a
language and being able to write clean, idiomatic code. After going through this book, that is
exactly what you can do. Whatever your background is, whatever programming languages
you know, as long as you understand object-oriented programming, this book helps you shift
into the C# and .NET ecosystem.
What do organizations like Microsoft, Google, and the U.S. Government have in common?
They all use C#. And for good reason. But why? C# is just another programming language.
It bears similarities to Java and C++, allows for both object-oriented and functional
programming, and a large open-source community widely supports it. Great. Now, why
should you care? In this chapter, we explore that question in-depth, but let me reveal a
couple of spoilers: C# excels at allowing you to create scalable software. To start writing C#,
all you need is the .NET flavor SDK of your choice (more on that in chapter 2) and perhaps
an IDE. The language and runtime are open-source.
Any time you look online for C#, chances are you come across the .NET Framework. A
good way of thinking about the .NET Framework is that it is your warm blanket, a warm fire,

©Manning Publications Co. To comment go to liveBook


3

and a mug of hot chocolate on a winter day, providing you with everything you need. Filled
with libraries that encapsulate low-level Windows APIs, expose commonly used data
structures, and wrappers for complicated algorithms. Since daily development in C# almost
certainly involves the .NET Framework or .NET Core, we explore these frameworks where
appropriate.
For those of you with prior experience in C#: this book sits between beginner and
advanced resources. With this book in hand, you can bridge the knowledge gap and prepare
yourself for advanced concepts. The first two chapters may seem a bit basic to you. I invite
you to not skim over these. It is always good to refresh your knowledge.

1.1 Why work in C#?


You already are familiar with a programming language other than C# and probably like using
it very much, so why should you use C#? Perhaps you got hired by a company that only uses
C#. Or maybe you just want to see what the fuss is all about?

Scalable Maintainable Developer Friendly

Multiplatform Mature native libraries Large community

Free to use Self-documenting code Excellent documentation

Figure 1.1 C# supports scalable software development due to its multiplatform capabilities. C# is open-source,
and therefore free to use. The language contains mature native libraries that help with secure coding and
promotes self-documenting code. This helps us in writing maintainable code. There is also a massive online
community around the language and fantastic documentation provided by Microsoft. This helps a developer
get up to speed quickly with the language.

So why C#, then? Well, I promise not to repeatedly tell you that C# is a “strongly typed
object-oriented programming language that enables cross-platform development of scalable
enterprise software.” You are likely already aware of that, and it is hardly the most exciting
sentence to dissect. In this section, we cover the buzzwords in that definition once and do
not touch on it again. At the risk of sounding like I’m employed by Microsoft’s marketing
department, for the rest of this section we focus on some highlights and use cases of C#:

1. C# enables development of scalable software in an economical way. Scalability and


economical solutions are important because enterprise development is the bread and
butter of C#. Because C# is open source, the barrier of entry to the language is low
and open to many.

©Manning Publications Co. To comment go to liveBook


4

2. C# can improve code stability and is maintainable because of its support for self-
documenting code, secure libraries, and ease of use.
3. C# is developer-friendly and easy to use. There’s nothing worse than discovering that
the programming language you want to use does not have good support for the things
you love (such as a stable package manager, testing libraries for Test-Driven-
Development, and a cross-platform runtime).

Of course, writing scalable, maintainable, and developer-friendly “clean code can be done in
most (if not all) programming languages. The difference lies in the developer experience.
Some languages are really good at guiding you in writing clean code while others are not. C#
is not perfect, but it does try and help you in this regard.

1.1.1 Reason 1: C# is scalable and economical


When we talk about maintainability in this book, we mean the ability to fix bugs, change
functionality, and address other issues without unintended side-effects This sounds like an
obvious requirement for any programming language, but it is very hard to implement. C#
has introduced features throughout its life cycle that improve maintainability (and therefore
safe extensibility) of large codebases. Think for example about generics, LINQ, and .NET
Core. We discuss these three things throughout the book, but they are examples of the
platform exposing functionalities that can help you write better code.
For a company, maintainability might not be their number one priority on the surface, but
if you develop code that is maintainable (meaning clean code that is easily extendable and
backed by tests), development costs drop. Development costs dropping when writing
maintainable code may seem counterintuitive at first. Maintainable code takes longer to write
and architect, driving up the initial costs of development. However, imagine what happens
after a little while when a user discovers a bug or they want an additional feature. If we write
maintainable code, we can easily find the bug (and fix it). Adding the feature is simpler since
the code base is extensible (think about the Open/Closed principle and polymorphism). If we
can easily extend and fix a codebase, development costs go down.

Open/Closed Principle (Clean Code)


In 1988, the French computer scientist Bertrand Meyer (creator of the Eiffel programming language), released a book
called Object-Oriented Software Construction (Prentice Hall, 1988). The release of Meyer’s book was a pivotal
moment in the history of object-oriented programming and design. Meyer introduced the “Open/Closed Principle”
(OCP). The OCP is aimed at improving the maintainability and flexibility of software designs. Meyer says the OCP
means that “software entities (classes, modules, functions, etc.) should be open for extension, but closed for
modification.”
But what does the OCP mean in practical terms? To examine that, let’s apply the OCP to a class: we deem a class
“open” for extension and “closed” to modification if we can add functionality to the class without changing the
existing functionality (and therefore potentially breaking parts of our code). If you abide by that rule, the odds of you
introducing a regression (or new bug) in the existing code are much smaller than if you try to force in the bug fix or
new feature with no regard for maintainability and extensibility.

©Manning Publications Co. To comment go to liveBook


5

1.1.2 Reason 2: C# can improve code stability


In the previous section, I explained that development costs go down in the long run if you
write maintainable code. The same story goes for stability. It is not a giant leap to go from
maintainable code decreases development cost to stable code decreases development cost.
What does stability mean? Some people say that stability means a lack of bugs, others say
guaranteeing a certain uptime percentage is what stability is all about. The way to achieve
both interpretations is by writing code that is secure and well-tested. By allowing for explicit
static typing and defensive coding practices, C# helps you write stable code.

1.1.3 Reason 3: C# is developer-friendly and easy to use


Enterprise development is the bread-and-butter of C# development. It is where C# and .NET
shine. What would your ideal codebase look like in an enterprise environment? Perhaps you
would like a codebase that is easily navigable with a solid package manager and backed by
tests (unit, integration, and smoke).
Let’s also throw in excellent documentation (but only where needed. As in most other
languages, self-documenting code is the standard in C#) and cross-platform support.

DEFINITION Self-documenting code means code that is written clearly enough that we need no comments
to explain the logic. The code documents itself. For example, if you have a method called
DownloadDocument we have some inkling of what the DownloadDocument method does. There is no
need to add a comment saying that the logic inside the method downloads a document.

To top things off, perhaps we can have some good integration with some cloud service for
continuous integration and delivery (CI/CD)? A pragmatic view tells us that the likelihood of
you having such a codebase is not very high. Of course, this is an unrealistic wish list for
most scenarios. However, if you wanted to do some of these things (or all of them, if you are
adventurous), C# does not work against you. There are existing workflows, functionalities,
and native libraries to get you 99 percent of the way there.
Developers coming from a language such as Java should see some familiarity in the
project structure. While there are some differences, they are not large. We discuss C#
project structure in depth throughout the book. Another important difference between Java
and C# highlighted in the book are streams. They mean very different things depending on
whether you work in Java or C#.
.NET also has support for several popular testing frameworks. Microsoft provides the
“Visual Studio Unit Testing Framework” which contains (and by extension is sometimes
called) “MSTest”. MSTest is just the command line runner for the Visual Studio Unit Testing
Framework. Other commonly testing frameworks are “xUnit” and “nUnit”. There is also
support for Moq (Moq is very similar to Java’s Mockito or Go’s gomock. We learn more about
using Moq with unit tests in section 10.3.3), SpecFlow (behavior-driven development similar
to Cucumber), NFluent (a fluent assertion library), FitNesse, and many more.
Lastly, you can run C# on a host of platforms, albeit with some limitations (some older
platforms are restricted to older versions of C# and the .NET Framework). With .NET Core,
you can run the same code on Windows 10, Linux, and macOS. .NET Code started as a

©Manning Publications Co. To comment go to liveBook


6

spinoff of the .NET Framework, but is now merging with .NET Framework (and other
frameworks) to create .NET 5. There are even ways to run C# code on iOS and Android
through Xamarin, and on PlayStation, Xbox, and Nintendo Switch platforms through Mono.

1.2 Why not work in C#?


C# isn’t the best choice for everybody under every circumstance. It is imperative that you
choose the best tool for the job.
C# works well in a wide variety of situations, but here are a few potential use-cases you
might want not want to use C# and .NET for:
• Operating system development
• Real-time operating system driven code (embedded development)
• Numerical computing

Let’s examine briefly why C# might not be an ideal fit for these use cases.

1.2.1 Operating system development in C#


Operating system (OS) development is an incredibly important corner of software
engineering. Not many people develop OSes. Developing an OS takes a bucket load of time
and commitment, with codebases routinely going into millions of lines of code, developed
and maintained over many years and sometimes decades.
The main reason C# is not suitable for OS development comes down to spotty support for
manual memory management (unmanaged code) and C#’s compilation story. While C#
allows the use of pointers when using “unsafe” mode, it does not rival a programming
language like C in ease-of-use for manual memory management.
Another problem with using C# to develop an OS is its partial reliance on a JIT compiler
(more on this in chapter 2). Imagine having to run your operating system through a virtual
machine. Performance would be a problem since the virtual machine has to play catch up all
the time to run the JITed code. That is like what happens when .NET code runs on your
machine. This critique means that a fully statically compiled language is a better fit for OS
development.
Yet, there are examples of OSes developed in higher-level languages. For example, Pilot-
OS (created by Xerox PARC in 1977) was written in Mesa 1 , a predecessor of Java.
If it interests you to learn more about operating system development, the wiki for the
osdev.org community is an excellent resource (wiki.osdev.org). There you can find guides to
get started, tutorials, and reading suggestions.
Resources for learning C include Jens Gustedt’s Modern C (Manning, 2019) and the
classic book The C Programming Language by Brian Kernighan and Dennis Ritchie (Prentice
Hall, 1988).

1 The name “Mesa” is a pun referring to the programming language being “high-level”, just like the isolated elevated hill with a flat top.

©Manning Publications Co. To comment go to liveBook


7

1.2.2 Real-time operating system embedded development in C#


Similar to OS development (section 1.2.1), real-time-operating-system (RTOS) driven code,
which you most often find in embedded systems, sees large performance issues when run
through a virtual machine. An RTOS scans code linearly, in real-time, and executes the
instructions at a configurable interval ranging from one operation per second to many times
per microsecond, depending on the wishes of the developer and the capabilities of the
microcontroller or programmable logic controller (PLC) the code runs on. A virtual machine
gets in the way of true real-time execution due to added latency and overhead at runtime.
If you want to learn more about RTOS-driven code and embedded development, several
highly regarded books have been published. For example, David E. Simon’s An Embedded
Software Primer (Addison-Wesley Professional, 1999), or Elecia White’s Making Embedded
Systems: Design Patterns for Great Software (O'Reilly Media, 2011).

1.2.3 Numerical computing and C#


Numerical computing (also called numerical analysis) is a field of computing concerning itself
with the study, development, and analysis of algorithms. People (usually computer scientists
or mathematicians) working in numerical computing use numerical approximation to solve
problems in about every branch of science and engineering. From a programming language
perspective, it has unique challenges and considerations. Every programming language can
evaluate mathematical statements and formulas, yet some are specifically built for this
purpose.
Consider plotting graphs. C# can absolutely handle plotting, but what performance and
ease-of-use does C# offer when compared to something like MATLAB? (MATLAB is both a
computing environment and a programming language created by MathWorks.) The short
answer is that it doesn’t compare. Graphics programming in C# sees you working in either
something like WPF (which uses Direct3D), OpenGL, DirectX, or a different third-party
graphics library (usually aimed at video games). With MATLAB, you have a language that ties
into an environment build to render complicated 3D graphs. You can literally call plot(x, y)
and MATLAB plots your graph for you.
So, C# can do numerical computing but does not offer the same ease-of-use as a
language with high-level libraries and abstractions dealing with graph plotting like MATLAB
does. If it interests you to learn more about MATLAB or numerical computing, some available
resources on these topics include Richard Hamming’s Numerical Methods for Scientists and
Engineers (Dover Publications, 1987), Amos Gilat’s MATLAB: An Introduction with
Applications (Wiley, 2016), and the “Cody” tutorial program for MATLAB
(https://www.mathworks.com/matlabcentral/cody).

1.3 Switching to C#
Because of the similarity between languages, developers with a good understanding of a JVM
language (most notably Java, Scala, and Kotlin) or C++ may have an easier time with this
book than somebody coming from a non-C style language, non-virtual-machine-esque-based
language, or web languages such as Dart, Ruby, or Go (although Go could also be construed
as a “cloud” language). Coming from a non-C style language background does not mean that

©Manning Publications Co. To comment go to liveBook


8

C# is impossible to understand. You may find yourself rereading some passages twice, but in
the end, you’ll get there just fine.
If you come from an interpreted language such as Python, the .NET compilation process
may seem odd at first. Languages within the confines of .NET use a “two-step” compilation
process. First, code is compiled statically to a lower-level language called Common
Intermediate Language (CIL, IL, or MSIL for short; MS for Microsoft. It is somewhat similar
to Java bytecode, for the Java developers among us), which in turn compiles “Just-In-Time”
(JIT) to native code when the .NET runtime executes the code on the host. All this might
sound like a lot to digest suddenly, but in a few chapters, you will understand all the above.
If you come from a scripting language such as JavaScript, static typing might seem to
limit and frustrate you. But once you get used to knowing what your type is at all times, I
think you’ll like it.
And if you come from a language such as Go or Dart, where native libraries are
sometimes hard to find: The .NET Framework and .NET Core may surprise you with its rich
store of libraries. By providing functions for most things you can think of, the .NET libraries
are your primary source for functionality. A lot of applications written with .NET never use
any third-party libraries.
To get the housekeeping out of the way, let’s discuss tooling. We do not dive into how to
install an IDE or the .NET SDK in this chapter. If you have not installed a .NET SDK or an
IDE and want some help, there are a couple of quick installation guides in Appendix C. To
follow along with this book, you need to install the latest versions of .NET Core and .NET
Framework (separately) until the release of .NET 5. With the release of .NET 5, .NET Core
and .NET Framework merge. We examine this merger in the next chapter.
As mentioned before, C# is open-source and maintained by the community with help
from Microsoft. You don’t need to pay for a runtime, SDK, or IDE license. Concerning IDEs,
Visual Studio (the IDE we use in the examples in this book) has a free “community” edition
that you can use to develop personal projects and open-source software. If you like your
current IDE, chances are you can find a C# plugin for it. You can also use the command line
to compile, run, and test C# projects, although I encourage you to give the dedicated C#
tooling (Visual Studio) a chance as it provides the smoothest experience and easiest route to
writing idiomatic C# code.
Many concepts and techniques you have picked up elsewhere transfer to C#, but some
don’t. C# has matured more on the backend than it has on the frontend, as it is traditionally
mostly used for that purpose. A historical focus on backend development for C# does not
mean that the frontend experience is any less impressive. You can write a full-stack
application in C# without the need to touch JavaScript. Although this book focuses on
backend development, many of the concepts taught in this book help you on the frontend as
well. To further help you get familiar with C# and .NET, this book contains exercises and two
full-length kata walkthroughs (chapters 15 and 16) that reinforce the topics discussed
throughout the book.

1.4 The importance of “clean code”


Have you ever written a monster method with five nested for loops, a bunch of assignments
with random numbers (so-called “magic numbers”), and more documentation than code?

©Manning Publications Co. To comment go to liveBook


9

Imagine you are not the person who wrote the code, but a new developer that just joined
your team. How would you feel when you boot up your IDE, pull down the source code, and
see this method? Despair would not quite cover it. Now imagine that you placed all the
individual actions in your monster method in their own small methods (perhaps fewer than
five to ten lines of code). What would your monster method look like? Instead of being a
bunch of difficult-to-follow conditionals and assignments, with no clear path to understanding
unless you have specific domain knowledge, the code almost reads like a narrative. If you
name your methods well, your main method should read like a recipe that even the worst
cooks can follow.
When I refer to “clean code,” I refer to the coding practices evangelized by Robert C.
Martin in his videos (https://cleancoders.com/videos) and books Clean Code (Prentice Hall,
2008); Clean Architecture (Prentice Hall, 2017); and, with Micah Martin, Agile Principles,
Patterns, and Practices in C# (Pearson, 2006); and as well as through his compilation of the
“SOLID” principles (Single Responsibility Principle, Open/Closed Principle, Liskov Substitution
Principle, Interface Segregation Principle, and Dependency Inversion Principle). I explain
clean code principles fully when they come up in the book along with practical information on
how to actually use them.
At the end of the day, why bother writing clean code? Clean code works like a washing
machine for bugs and incorrect functionality. If we put our codebase in the Clean Code
washing machine, we see that once you refactor something to be more “clean,” bugs come
out and incorrect functionality stares at you with no place to hide. After all, “it all comes out
in the wash”.

Bugs

Code

Code
Clean Code Washing Machine

Figure 1.2 Clean Code is like a washing machine for your code. It takes your dirty laundry (your code), adds
soap and water (clean code principles), and separates the dirt from the clothes (separates the bugs from the
code). What it leaves you with are clothes (code) with less dirt (bugs) than you started with. Clean Code helps
you write code that contains fewer bugs.

This book contains sidebars with information on clean code topics. If the sidebars are clean-
code related, I denote them as such and explain both the concepts and how to apply them to
the real world. Appendix B contains a “Clean Code Checklist.” You can use the “Clean Code

©Manning Publications Co. To comment go to liveBook


10

Checklist” to determine whether you need to refactor the existing code. The checklist serves
as a reminder for some of the more forgettable (but still important) concepts.

1.5 What you will learn in this book


This book teaches you to write idiomatic and clean C# code. My goal is to provide you with a
practical approach on how to do that. It does not teach the C# language, the .NET
framework, or programming from the ground up. We follow a business case in which we
refactor an old API to be more clean and secure. Along the way, you learn many things. A
few highlights are
• Taking a codebase you inherited and refactoring it for security, performance, and
cleanliness.
• Writing self-documenting code that can pass any code review.
• Using Test-Driven Development to write unit tests alongside your implementation
code.
• Safely connecting to a cloud database through Entity Framework Core.
• Introducing clean code principles into an existing codebase.
• Reading Common Intermediate Language and explaining the C# compilation process.

So, what do you need to know to get the most out of this book? The expectation is that you
understand the basic principles of object-oriented programming (inheritance, encapsulation,
abstraction, and polymorphism) and are familiar with another programming language that
supports developing code through an Object-Oriented approach, even if not an intrinsic
feature of the language (be it C++, Go, Python, or Java).
After reading this book, you’ll write clean, secure, testable C# code that follows good
object-oriented design principles. Additionally, you’ll be ready to further deepen your
knowledge in C# through advanced resources. Some suggested readings for after this book
are Jon Skeet’s C# In-Depth, fourth edition (Manning, 2019), Jeffrey Richter’s CLR via C#.
fourth Edition (Microsoft Press, 2012), Bill Wagner’s Effective C#, second edition (Microsoft
Press, 2016), Dustin Metzgar’s .NET Core in Action (Manning, 2018), John Smith’s Entity
Framework Core in Action, second edition (Manning, 2021), and Andrew Lock’s ASP.NET Core
in Action, second edition (Manning, 2021).

1.6 What you will not learn in this book


This book aims to fill the gap between beginner and advanced C# resources. With that goal
come some consequences regarding what assumptions I make about your understanding of
C# and programming. As briefly discussed in section 1.5, I expect you to have some
professional programming experience and that you are comfortable with either the basics of
C# or a different object-oriented programming language.
What do I mean by that? To get the most out of this book, you should understand object-
oriented principles, and you can develop basic applications or APIs in your favorite
programming language. As a result, this book does not teach you some of the following
topics often present in a beginner programming book:
• The C# language itself. This is not a book along the lines of “Code C# from Scratch.”

©Manning Publications Co. To comment go to liveBook


11

Instead, I teach you how to take your existing C# or object-oriented programming


knowledge to the next level.
• Syntax around conditionals and branching statements not specific to C# (if, for,
foreach, while, do-while, etc.).
• What polymorphism, encapsulation and inheritance are (although we use these
concepts regularly in this book).
• What a class is and how we model real-world objects to classes.
• What a variable is, or how to assign a value to one.

If you are new to programming, I highly recommend going through a book such as Jennifer
Greene’s Head First C#, fourth edition (O’Reilly, 2020) or Harold Abelson, Gerald Jay
Sussman, and Julie Sussman’s Structure and Interpretation of Computer Programs, second
edition (The MIT Press, 1996) 2 before reading this book.
This book also doesn’t cover some more specialized ways to use C# as follows:
• Microservice architecture. This book does not go into depth on what microservices are
and how to use them. Microservice architecture is very much the trend and is useful
in many use cases, but is not related to C# or how you code like a pro. Three
wonderful resources to learn more about microservices are Chris Richardson’s
Microservices Patterns (Manning, 2018), Prabath Siriwardena and Nuwen Dias’
Microservices Security in Action (Manning, 2019), and Christian Horsdal
Gammelgaard’s Microservices in .NET Core (Manning, 2020).
• How to use C# with containerized environments such as Kubernetes and/or Docker.
While very practical and used in many enterprise development environments, knowing
how to use Kubernetes or Docker does not guarantee you can “code like a pro” in C#.
To learn more about these technologies, see Marko Lukša’s Kubernetes in Action.
second edition (Manning, 2020), Elton Stoneman’s Learn Docker in a Month of
Lunches (Manning, 2020), and Ashley Davis’ Bootstrapping Microservices with Docker,
Kubernetes, and Terraform (Manning, 2020).
• Concurrency with C# beyond multi-threading, basic parallelism (chapter 17), and
locks (chapter 6). We often find this topic in highly threaded and performance-critical
scenarios. Most developers don’t work with such code much. If you do find yourself in
that position, an excellent resource to learn more about concurrent programming in
C# is Joe Duffy’s Concurrent Programming on Windows (Addison-Wesley, 2008).
• The deep internal details of either the CLR or the .NET Framework themselves. While
interesting, knowing every little detail about the CLR or .NET Framework (.NET Core
included) is of little practical use for most developers. This book covers the CLR and
.NET Framework in some detail but stops where things get unpractical or unwieldy.
The "bible” for the CLR and .NET Framework is Jeffrey Richter’s CLR via C#, fourth
edition (Microsoft Press, 2012). Note that Richter’s book does not cover .NET Core (or
CoreCLR) as .NET Core was introduced in 2016.

There are two ways of reading this book: the recommended way is to read the entire book,
front to back and in order. If you are only interested in refactoring and best practices, you

2 Available for free from The MIT Press at https://mitpress.mit.edu/sites/default/files/sicp/index.html

©Manning Publications Co. To comment go to liveBook


12

can just read parts 3 through 6. That leaves part 7, which contains two coding kata
walkthroughs. These thematically tie into the rest of the book but do not form part of the
overall narrative. They cover some topics (parallelism, string concatenation performance in
memory, the Strategy design pattern) that any developer would not want to miss in their
toolbox.

1.7 How this book is structured


This book has a somewhat unconventional approach to its structure compared to a regular
technical book. Most technical books are reference books or can be read in any order. This
book is not a reference book, and to get the most out of it. you need to read the chapters in
order. The book is structured around seven parts:

1. “Using C# and .NET”: In chapter 1 we discussed what this book is, what it teaches,
and what it does not teach. Chapter 2 is a brief tour of the C# language and .NET
framework, focusing on what sets .NET apart from other platforms and the C#
compilation story.
2. “Inheriting Code”: In this part, I guide you through the exploration of a code base we
inherit. This part is a detailed walkthrough of the existing code base, with a discussion
on potential improvements and design flaws.
3. “Refactoring the database access layer”: Following part 2, we start to rewrite the
entire service. In part 3, we focus on creating a new .NET Core project and learn how
we can use Entity Framework Core to connect to a cloud (or local) database. Other
discussed topics include the Repository/Service pattern, virtual methods and
properties, and sealed classes.
4. “Refactoring the repository layer”: In part 4, we step into the lands of the
Repository/Service pattern and implement 5 repository classes. You also learn about
dependency injection, multithreading (including locking, mutexes, and semaphores),
custom equality comparisons, Test-Driven Development, generics, extension methods,
and LINQ.
5. “Refactoring the service layer”: The next step is to implement the service layer
classes. In part 5, we write 4 service layers from the ground up and talk about
reflection, mocking, coupling, runtime assertions and type checks, error handling,
structs, and yield return.
6. “Refactoring the controller layer”: Part 6 is the final step in our rewrite of the service
we initially inherited in part 2. This part sees us writing 2 controller classes, and has
us perform acceptance testing. Besides those topics, we also broach ASP.NET Core
middleware, HTTP routing, custom data binding, data serialization and deserialization,
and generating an OpenAPI specification a runtime.
7. “Coding Katas”: This part contains 2 full-length coding katas walkthroughs. The first
coding kata (chapter 15) revolves around the StringBuilder class, the Strategy design
pattern, and pausing threads. The second coding kata (chapter 16) discussed graph
theory, linked lists, and parallelism.

©Manning Publications Co. To comment go to liveBook


13

1. Start reading

5. Read chapters 6 - 9 Part 5

Part 1

Part 4
6. Read chapters 10 - 12

2. Read chapters 1 & 2

Part 6

YES
Interesting only in... Part 3 4. Read chapter 5

7. Read chapters 13 & 14


NO
8. Read chapters 15 & 16

Part 2 3. Read chapters 3 & 4


YES
Part 7 Want to learn more?

NO
9. Done

Figure 1.3 A flowchart of suggested routes to read this book. Follow the steps and answer the questions to
achieve your ideal reading experience. This flowchart is inspired by the book structure flowcharts in Donald
Knuth’s The Art of Computer Programming series.

A lot of chapters in this book (and some sections within chapters) have exercises designed to
test your knowledge of the material. You can complete these exercises quickly. I encourage
you to complete these when you encounter them, and to revisit sections you may have
skimmed or misunderstood.

1.8 Summary
• This book doesn’t cover “Programming 101.” It assumes knowledge of object-oriented
programming. This allows us to focus on practical concepts.
• C# and .NET are free to use and open source, yet partially maintained (and originally
created) by Microsoft. This means that there is a lot of community support and we can

©Manning Publications Co. To comment go to liveBook


14

rely on plenty of resources for help when issues arise.


• C# and .NET shine at scalable enterprise development with a focus on stability and
maintainability. This makes C# and .NET a perfect platform of choice for both
companies and individual developers.
• C# and .NET do not shine at Operating System Development, RTOS Embedded
Development, or Numerical Computing (or Analysis). For those tasks, C and MATLAB
fit better.

©Manning Publications Co. To comment go to liveBook


15

Tour de C# and .NET

This chapter covers

• The difference between .NET Core, .NET Framework, and other platforms
• The release of .NET 5
• The C# compilation process
• How to read Intermediate Language
Microsoft created the .NET Framework in the early 2000s. The original use-case for the .NET
Framework was developing enterprise Windows applications. The .NET Framework ties
together with a large collection of libraries. Whilst the .NET Framework and C# are often tied
at the hip, there are use cases for the .NET Framework without C# (we talk about some of
these when discussing the .NET Standard later on in this chapter). The two most important
pillars of what makes up the .NET Framework are the Framework Class Library (FCL; a
humongous class library that is the backbone of the .NET Framework) and the Common
Language Runtime (CLR; the runtime environment of .NET). In other words, The FCL
contains all the libraries you are likely to use and the CLR executes the code.
In this chapter, we discuss a couple of features of the .NET framework and contrast them
against implementations (and sometimes the lack thereof) in other platforms such as Java,
Python, and Go. After that, we learn about the C# compilation process by following a method
from C# to Common Intermediate Language to native code. These fundamental building
blocks allow us to have a solid foundation in our knowledge of the C# and .NET ecosystem. If
you are already very familiar with C# and .NET, this chapter is bound to have some
repetition for you. If nothing else, I suggest you read through section 2.4. The discussion on
the C# compilation process is deeper than what you find in most resources, and is assumed
knowledge in some advanced C# resources. To test your knowledge of the respective topics,
each section has exercises for you to try.

©Manning Publications Co. To comment go to liveBook


16

2.1 The .NET Framework compared to other platforms


For many people, the .NET Framework is synonymous with C#. After all, C# is the most
commonly used programming language using the .NET Framework and when you write C#,
most functionality you need is through the framework. Because of this relationship, over the
last twenty years, the C# and .NET Framework have both matured very well. In this section,
I compare four features of the .NET Framework that set it apart from other platforms.
The specific functionalities discussed in this section can be found in table 2.1. Note that I
only compared native functionality (no third-party libraries needed). I chose the
functionalities in table 2.1 because they represent a range of daily tasks and types you might
encounter when developing in C#. This section is not meant to be an exhaustive study of the
.NET Framework nor of its counterparts. There are also plenty of features available in other
platforms that the .NET Framework does not have. Note that this table is always in flux, as
technologies add and drop support for features. At some point in time, it will be outdated.

Table 2.1 Comparison of .NET Framework functionality versus other platforms (native/built-in
support only)

Functionality .NET Java Go Python JavaScript C++ Ruby R Haskell C

Tuples Yes No No Yes No Yes No Yes Yes No

Events Yes Yes No No Yes No No Yes Yes No

SQL Yes Yes Yes Yes No No Yes No No No

CSV Parser Yes No Yes Yes No No Yes Yes Yes No

I chose the platforms in table 2.1 because of their widespread use and diversity in targeted
use cases (back-end, front-end, or full-stack). Developers use many other languages (think
about PHP, Groovy, Objective-C, Perl, Pascal, COBOL. The list goes on), but we have to draw
a line somewhere (even if it is an arbitrary one).

2.1.1 The .NET Framework compared to other platforms: tuples


In this section, we look at how the .NET Framework supports tuples (by way of C#), what
they are, and how tuples are supported in other platforms. A highly requested feature by the
.NET Framework user community, tuples were introduced into the .NET world in 2018 as part
of the .NET Core Preview channel (.NET Core is a spinoff of the .NET Framework. We discuss
.NET Core in section 2.2). In practical terms, a tuple is a type that can represent a set (or
row) of values. Looking at the formal definition as found in set theory, we can say that a
tuple is a finite sequence consisting of terms wherein no term can occur twice. So, <x, y> is
a valid tuple, but <x, y, x> is not. This uniqueness rule does not prohibit us from using
variables pointing to the same spot in memory in our C# tuples, as they are considered
equal but not identical. So, when would we use a tuple? Tuples allow us to return multiple
variables out of a method without storing them into a throw-away object.

Table 2.2 Comparing the availability of Tuples across platforms

©Manning Publications Co. To comment go to liveBook


17

Functionality .NET Java Go Python JavaScript C++ Ruby R Haskell C

Tuples Yes No No Yes No Yes No Yes Yes No

In C#, the syntax to create a tuple is, for example:

(string, string) myTuple = ("Code C#", "Like A Pro");

Because tuples are immutable, they are great at representing a database record. You can
mix and match types within a tuple, as long as the declaration matches the assignment. This
means that you can make your tuples as lengthy and complicated as you want, as long as
you assign the tuple to a set of objects with the same types (and order of types) as your
tuple variable. Listing 2.1 has examples of both a valid assignment where the variable and
assigned set have the same types (and order) and one where it does not.

Listing 2.1 Tuples in C#


(string, int) myTuple = ("Age", 25); #A
(string, int, float, short, byte) myTuple = ("Cost", 2, 30.1, 9, 1); #A

(string, float) myTuple = ("Name", "Jort"); #B

#A These compile
#B This does not compile. Notice the type error in the second argument: float versus string.

When attempting to compile the invalid tuple in listing 2.1, we run into a compiler exception
(as shown in figure 2.1). The exception tells us it cannot automatically convert between a
string type and a float type. We told the compiler we are expecting a (string, float) yet
are assigning (string, string).

Figure 2.1 The code in listing 2.1 threw an exception telling us we cannot implicitly convert between strings
and floating-point types. CS0029 is the error code for this error.

Besides mixing types, you can also “deconstruct” tuples and use them as “named tuples”
(listing 2.2).

Listing 2.2 Deconstructed / named tuple in C#


(string companyName, bool isBankrupt) myTuple = ("Manning", false);

companyName = "Kodak";
isBankrupt = true;

Table 2.2 tells us that support for Tuples is not widespread amongst programming languages
with the most notable exceptions being Java and Go.

NOTE You can pronounce “tuple” in two ways. I prefer ‘tjʊpəl (rhymes with “scruple”) but some people say
ˈtʌpəl (rhymes with “couple”).

©Manning Publications Co. To comment go to liveBook


18

2.1.2 The .NET Framework compared to other platforms: events


This section briefly covers the differences in the implementation of events in C# and other
platforms (notably Java), as well as why some platforms do not support events.
Development following the event-subscriber (or observer) pattern has been a staple of C#
development for a long time. The event-subscriber pattern allows you to notify other parts of
your code of a result or perform callbacks.

Table 2.3 Comparing the availability of events across platforms

Functionality .NET Java Go Python JavaScript C++ Ruby R Haskell C

Events Yes Yes No No Yes No No Yes Yes No

Java also supports events, but less explicitly than C#. Whereas C# knows the event
keyword, Java does not have any special syntax for events. JavaScript, on the other hand,
knows a thing or two about events and has very good support for them.

2.1.3 The .NET Framework compared to other platforms: SQL


There will be a time in your career when you need to connect to a database (be it a SQL or
NoSQL database). When you go down the rabbit hole of using a database and querying it in
your preferred programming language, chances are you quickly discover that it is a bit of a
headache. The code needed is usually very verbose and more complex than it needs to be.
Some languages don’t provide built-in database and SQL libraries and you have to use a
third-party library. For .NET, however, there are excellent built-in libraries that allow you to
connect to and query from a SQL database in less than five lines of code. In this section, we
look at exactly that and learn how to connect to and query from a SQL database without
using a fancy third-party library.

Table 2.4 Comparing the availability of SQL across platforms

Functionality .NET Java Go Python JavaScript C++ Ruby R Haskell C

SQL Yes Yes Yes Yes No No Yes No No No

Looking at table 2.4, we can quickly see that a fair number of platforms support SQL out-of-
the-box to some extent. It also comes as no surprise that JavaScript and Ruby do not
provide libraries to query SQL databases, as web platforms should not connect to databases
directly (mainly for security reasons).
The .NET Framework has two main ways of connecting to SQL databases:
• using the built-in SqlConnection classes
• using Entity Framework (or Entity Framework Core for .NET Core).

It is up to you which one you want to use. Entity Framework Core is an open-source Object-
Relational Mapping (ORM) package maintained by Microsoft and the community that is
deeply ingrained in .NET. It is the easiest way of connecting to a database and it has drivers

©Manning Publications Co. To comment go to liveBook


19

for most database flavors. On the other hand, the built-in .NET Framework libraries offer a
stable, non-abstracted way of querying a database and retrieving information.
In this book, we use Entity Framework Core (EF Core) when we go to connect to our own
database. We use EF Core because as the database complexity grows, so does the hassle of
not using an abstraction layer. The book discusses what it means to use an ORM, why you
would want to use one, and how to use EF Core. That being said, it is good to see how you
can connect to a SQL database in .NET Framework without an ORM.
To connect to a SQL database in C# without an ORM, we have to follow a couple of steps:
• Create a new SqlConnection object
• Open a connection to the database
• Specify the query we want to perform
• Execute our query
• Close our SqlConnection and query objects by disposing of them

Since the SqlConnection class implements the IDisposable interface, we need to dispose of
it after using it. If you are not familiar with garbage collection: disposing of an object means
we tell the garbage collector we do not need to use the object anymore and request that it
removes it from memory in the next garbage collection cycle. We only need to explicitly go
through this process for types that hold onto resources such as a SqlConnection (which can
hold onto an open connection to a database). If we do not dispose of such an object, chances
are it remains in memory for the duration of the application’s runtime. This is what we call a
memory leak. The easiest and most used way to dispose of an object is to wrap it in a using
statement. This scopes the object to that particular block of code and disposes of the object
when the code block is finished.
Next, we need to open the connection to our database. We do this by calling upon the
Open method of the SqlConnection instance. If you don’t “open” your SqlConnection, any
query fails since there is no open connection to the database. To use an opened connection,
we need a query to execute. To specify a query, we create a new instance of SqlCommand.
One of the available constructors for SqlCommand takes in a string. This string is the SQL
command you want to execute; in the case of listing 2.3 we want to select all records from a
table called “myTable”: “SELECT * FROM myTable”.
Then, we call the ExecuteScalar method on the SqlCommand containing our SELECT
query. There are a variety of ways you can execute a SqlCommand. ExecuteScalar returns a
single column of serialized data (one value). We store this data in a variable of type object
(all classes and types inherit from type object). You could further process this to a different
data structure if you want. Finally, since SqlCommand also implements IDisposable, we need
to dispose of it. If you don’t want to wrap a disposable object in a using block, an alternative
way is to explicitly call [object].Dispose when you are done with the instance. Listing 2.3
shows both approaches.

Listing 2.3 Connecting to a database without an ORM in C#


using (SqlConnection connection = new ➥SqlConnection(connectionString)) #A
{
connection.Open(); #B

©Manning Publications Co. To comment go to liveBook


20

SqlCommand command = new SqlCommand("Select * FROM myTable ", ➥connection); #C

object result = command.ExecuteScalar(); #D


command.Dispose(); #E
}

#A Create a new SqlConnection and wrap it in a using statement.


#B Open the connection to the database
#C Create a new SqlCommand and pass in our SELECT query.
#D Executes the SqlCommand and returns a single column of serialized data.
#E Dispose of SqlCommand.

NOTE Most classes in the .NET Framework and C# use Pascal-Case style capitalization (concatenated words
all start with capitalized letters: SqlCommand) for methods and attribute names. Variables and properties (if
not public), however, use camel casing (each word after the first starts with a capital letter: tennisBall).

Class implements IDisposable

Dispose safely of the object Wrap in a “using” statement

Recycling with C#

Figure 2.2 Recycling a disposable object in C#. Step 1: the class implements IDisposable. Step 2: We wrap it in
a “using” statement. Step 3: we dispose safely of the object. Just like in real-life recycling, disposing of
something safely is of paramount importance to the health of our environment.

NOTE To use SqlConnection you have to “import” the System.Data.SqlClient namespace. In C#


you can import libraries and namespaces through a using statement at the top of the class: using
System.Data.SqlClient; The code sample above reuses the using statement slightly differently.

2.1.4 The .NET Framework compared to other platforms: CSV parser


Imagine your boss tasks you with creating an ETL (Extract, Transform, Load) application that
heavily relies on CSV files for input. Now imagine you have to parse this CSV file without a
library using something like string.Split(,). That is the situation in JavaScript, C++, and
C. CSV parsing is one of those functionalities that can eat up your time and keeps coming up

©Manning Publications Co. To comment go to liveBook


21

time and time again. Luckily, the .NET Framework provides an excellent built-in CSV parser
that makes our life a lot easier.

Table 2.5 Comparing the availability of CSV Parser across platforms

Functionality .NET Java Go Python JavaScript C++ Ruby R Haskell C

CSV Parser Yes Yes Yes Yes No No Yes Yes Yes No

Since the library exposed in the .NET Framework is not just meant for CSV files, it is called
TextFieldParser. It is part of the Microsoft.VisualBasic.FileIO namespace. You
might think, how can I use a library in Visual Basic in C#? Since many languages implement
the .NET Framework and compile down to the same Intermediate Language (discussed in
section 2.2), we can use code compiled against any languages using .NET in any other
language using .NET.
To parse a CSV file in C# using TextFieldParser, follow a couple of simple steps:

1. Create an instance of TextFieldParser, wrapped in a using statement.


2. Give your instance of TextFieldParser the path to the file you want to parse.
3. Configure your TextFieldParser.
4. Loop over the file until you reach the end while parsing the data into your data
structure.

Starting with the first three items, create your TextFieldParser, give it the path to the file
(as a string), and wrap it in a using statement:
using (TextFieldParser parser = new TextFieldParser(myFilePathString))
{

}

Now we need to configure our parser. There are a myriad of options you can set (what your
comment tokens are, whether your data encloses fields in quotes, whether you want to trim
white space, what the field width is, and more) but we are most concerned with specifying
our delimiter character. We set our delimiter to a comma character but you can set it to any
character you want. You can also use multiple delimiters.

parser.SetDelimiters(","); #A

Before we can grab the fields from the file, we need to declare and initialize a collection to
store the information in:

List<string[]> parsedFields = new List<string[]>();

We loop over the parser until its EndOfData property evaluates to true (it’s a Boolean), parse
the found data into a string array, and add the string array to parsedFields.

while (!parser.EndOfData)
{
string[] fields = parser.ReadFields();
parsedFields.Add(fields);
}

©Manning Publications Co. To comment go to liveBook


22

That, in a nutshell, is how you parse a CSV file in C#. You can, of course, process the data
further into an object of your liking. To wrap up, this is the complete code snippet:

using (TextFieldParser parser = new TextFieldParser(myFilePathString))


{
parser.SetDelimiters(",");

List<string[]> parsedFields = new List<string[]>();


while (!parser.EndOfData)
{
string[] fields = parser.ReadFields();
parsedFields.Add(fields);
}
}

2.1.5 Exercises
EXERCISE 2.1
Fill in the blanks: To connect to a SQL database, you can use an ORM such as _, or do it
yourself with the help of _.

a) Microsoft SQL ORM Classic


b) Entity Framework
c) SqlConnection
d) SqlParser
EXERCISE 2.2
True/False: The types in a tuple all need to be the same.

a) True
b) False
EXERCISE 2.3
What does this error mean: “Cannot implicitly convert type bool to int”?

a) The code tries to convert an integer to a bool type. The compiler does not know
how to do this.
b) The code tries to convert a bool to an integer type. The compiler does not know
how to do this.
c) The code tried to optimize your code and generated an invalid conversion.
EXERCISE 2.4
True or False: Because the SqlConnection class implements the IDisposable interface, we
do not have to manually clean up any resources left by the SqlConnection logic.

2.2 What is .NET Core?


The basic premise of .NET Core is simple enough: “Run .NET Framework code on any
platform”. To accomplish this, a re-architecture of the .NET Framework took place. Much of
the existing .NET Framework relies on Windows APIs through COM/Interop. This code could

©Manning Publications Co. To comment go to liveBook


23

not be copied over since other platforms would not have the same APIs. This made things
like working with graphics and GUIs tremendously difficult on a platform other than
Windows.

NOTE COM Interop is a technology (part of the CLR) that allows the .NET Framework to interact with COM
objects and vice versa. COM (Component Object Model) objects are low-level models, often written in C, used
as the basis for many internal Windows APIs.

The initial focus of .NET Core was put on web services. This removed the immediate concern
of graphics programming on a new platform, although movement in that space has been
made recently; there are third-party libraries that can help with GUI development on other
platforms, mainly by replacing the provided components with components compatible with
the native graphics APIs of a specific platform. Since .NET Core uses the Mono compiler (an
open-source .NET Core compiler created for Linux/Mac and the Unity video game engine),
there are differences in how code compiles between the .NET Framework and .NET Core
(.NET Framework uses the Roslyn compiler by default). Since .NET Core 3 adheres to the
.NET Standard, Windows Forms, Windows Presentation Foundation, and Universal Windows
Platform programs can target .NET Core 3. This, however, has not proven to be a hurdle for
the adoption of .NET Core. Many companies are using .NET Core for their web back-ends
such as services and APIs. Developers can write these back-ends once and run on Windows,
macOS (previously OSX), and Linux with the same code base

.NET Standard
The .NET Standard is a specification that has been used to develop a variety of implementations of .NET: .NET
Framework, .NET Core, Mono (the cross-platform technology that .NET Core is built on), Unity (video game
development), and Xamarin (iOS and Android development). These have different use-cases but are inherently very
similar. Developing an implementation against the .NET Standard means that code-sharing between implementations
is as seamless as possible.

©Manning Publications Co. To comment go to liveBook


24

The .NET Standard

.NET Framework Unity


.NET Core Mono Xamarin
Figure 2.3 The .NET Standard is implemented by .NET Core, the .NET Framework, Mono, Xamarin, and Unity.

The .NET Standard contains information on what APIs are available for use when interacting with the CLR (the
runtime on which C# depends). Before .NET Standard, there was no real way of making sure that your code or library
would work across .NET implementations besides using Portable Class Libraries (PCL). PCLs are libraries that can be
shared among projects but can only target a specific version of a .NET implementation (or “profile”). Today we call
these PCLs “profile-based PCLs.” Libraries targeting a .NET implementation adhering to the .NET Standard are also
PCLs, but instead of targeting a specific implementation, they target a version of the .NET Standard. To differentiate
between profile-based PCL’s, we call these “.NET Standard-based PCLs.” The .NET Standard encapsulates a lot of the
Windows APIs used by libraries written in the pre .NET Standard era (and therefore profile-based PCLs). As a result, we
can use those libraries in any .NET Standard implementation of .NET without a problem. The first version of the .NET
Framework to implement the .NET Standard was 4.5.
As with all modern .NET developments, the .NET Standard is fully open source. The code and documentation live
on GitHub (https://github.com/dotnet/standard).

.NET Core has transitioned from yet another spinoff into the future of the .NET ecosystem. In
fact, the next step in the .NET story is the merger between .NET Framework 4.x and .NET
Core 3.x. The next release of .NET is.NET 5, but in essence, it also is .NET Core 4, and it
replaces the current iteration of the .NET Framework. For any new development in .NET, I
highly recommend to use .NET Core 3 for now, but switch to .NET 5 when a public release
client is released. The reason for this is that you still get the most up-to-date version of .NET
Core with the least amount of work when it comes time to switch to .NET 5. All the lessons
learned in this book transfer over smoothly to .NET 5.

©Manning Publications Co. To comment go to liveBook


Random documents with unrelated
content Scribd suggests to you:
need expect nothing to come of it. To-day I am in doubt.... I desired
to hold myself free from—er—such things as marriage. Doubtless
that, also, was a mistake.... I am open-minded.”
“You—you—are open-minded!” Carmel gasped out the words.
“Exactly. I have determined to allow the emotion to follow its natural
course, without interference by myself. Even if it results in marriage
with you, I shall not interfere.”
“Of all things,” said Carmel.
“Meantime, while the more important matter is working itself out, let
us endeavor to be friends.” As he said this there came into his voice
a wistfulness, a humility which touched her. Her eyes filled. She held
out her hand.
“Friends!... Of course we shall be friends! You must overlook my bad
temper. I have so many faults.”
His eyes glowed, his face became animated. “You,” he said, eagerly,
“are very lovely. You are—er—wonderful....” He stared at her as if
she had been an apparition. Carmel caught her breath and turned
away abruptly.
So much for Evan Pell’s effort to break through his chrysalis shell....
The fates had not determined if he were to become a moth or a
butterfly....
At that very hour Abner Fownes was opening his mail. His frame of
mind was not of the pleasantest, though he had succeeded in tiding
over the day before a situation financially threatening. The condition
of his affairs was wearing upon him. Constant calls for money,
demands upon his shiftiness to prevent a débâcle, never-failing
watchfulness, bore heavily upon the man. It was not easy to maintain
his attitude of high-spirited public citizen. It was not simple to keep
beneath the surface the man who lurked under the skin of the
fatuous cat’s-paw. It was difficult to maintain the pretense of being
used by smaller men, when constantly he had to twist smaller men to
his own ends.
Now he opened with trepidation a letter from a lumber concern with
which his dealings had been extensive.
We have received yours of the 20th with respect to
renewing your note for $18,750 which falls due two weeks
from to-day. We regret that in present conditions this is
impossible, and must ask you to take up this paper without
fail.
Fownes crumpled the letter in his hand and stared at the paneling of
his office as if he hoped by the mere venom of his look to reduce it to
ashes. His pudgy, beautifully tailored shoulders moved upward so
that his short neck disappeared and his ears rested upon his collar.
Then he expelled his breath. He arose and went to the safe, which
he opened—to which he alone possessed the combination—and
took from its resting place the red leather book in which he kept the
true record of his and his company’s condition. This he carried to his
desk, and for many minutes he studied it, hoping against hope for
some expedient to make itself apparent.... There was no expedient.
He returned the book to its place and locked the safe; then he
twisted the handle of the telephone insistently, and gave Central the
number of the Court House.
“Deputy Jenney,” he said, arrogantly.
The deputy answered.
“Come to my office immediately,” he said. “Never mind who sees.
This is imperative.... At once.” Following that, he waited.
Deputy Jenney entered, breathless, and stood panting.
“Jenney,” said Fownes, “I’ve determined to make another
investment.”
“Eh? Already.... Why, we hain’t hardly got the last off’n our hands. It’s
takin’ a chance, says I, and crowdin’ the mourners.”
“I’m running this business, Jenney.... This next is to be no retail deal,
either. It’s wholesale.”
“You—you want to go easy. By golly! Mr. Fownes, so much stuff
comin’ in is goin’ to git somebody mighty curious.”
“If you’re sheriff, Jenney, what will the curiosity amount to?”
“Federal officers!”
Fownes shrugged his shoulders. “I’ll see to your appointment as
sheriff. You attend to organizing everybody to receive the shipment.
We’ll need all available space and all outlets. I’m going to fetch in
enough this time to flood the county.”
“You know what you’re doin’,” Jenney said, sullenly, “but what with
that damn paper a-peckin’ at us all the time——”
“Nobody reads it, Jenney. And you’ll be sheriff.”
“I’ll do my dumdest—but I don’t like it.”
“And I don’t care whether you like it or not. And that’s that. Better see
Peewee first.”
“When’s it comin’?”
“Inside of ten days.... And, Jenney, I don’t believe the paper’s going
to bother much longer.”
“Eh?”
“I’m going to—er—give that girl a hint of our plans.”
“What?”
“I’m going to give her a tip, as they say. She’ll investigate, and that
professor will investigate.”
“Like Sheriff Churchill did?”
“The result,” said Fownes, “will be similar.”
CHAPTER XVI
“YOU are not,” said Evan Pell to Carmel Lee, “familiar with
laboratory practice—er—with chemical analysis, for instance.”
“I know nothing about it?”
“I judged not,” he said, unwittingly reverting to his patronizing
manner. “However, it seems to me the individual who searches for
truth—in the happenings of the day—would be better fortified for his
labors if he applied the methods of the chemist.”
“As, for instance?”
“Let us suppose there has been a crime. The crime is a result. An
inevitable result of the combination of certain elements. Given the
crime, the chemist should be able to analyze it and to separate its
elements.”
“I believe that is the method of story-book detectives.”
“No.... No.... This is science, logic. A simple example. You hold a
substance in your hand. You moisten it with iodine. If the substance
turns purple you know starch is present. Do you see?”
“I’m sure I don’t see.”
“What do you think of Abner Fownes?” he asked, with
uncharacteristic swerving from the subject.
“I think he is abominable.”
“Possibly.... But impersonally, as an individual—what then?”
“He is a pompous, self-deceiving, hypocritical poseur.”
“Uh!... As to intelligence?”
“As your chemist would say—a trace.”
“I fear,” he said, “you have neglected to moisten him with iodine.”
“What do you mean?”
“I mean,” he said, “that you have utterly failed to comprehend what
you are facing—what it is you have to do in this headstrong crusade
of yours against the liquor smugglers.”
“What has that to do with Abner Fownes?”
“That,” he said, “is the big question.”
“But why should he? That is absurd. Perhaps the smugglers are
using him as a cat’s-paw in some manner—but he’s rich. There’s no
need. These men take the risks they must for profit.”
“Miss Lee,” he said, “you—er—challenged me to investigate this
affair. I promised to do so.... I have set about it in an orderly manner.”
“So I imagine,” she said, a trifle wearily.
“I have started with the compound itself—with the fact that we know
there exists a wholesale traffic in liquor, from which a huge profit is
derived. This is compounded of many small elements. I think we may
take it as fact that the hunchback, Peewee Bangs, is an element;
that his hotel is another element; that Deputy Jenney is a rather
important ingredient. For myself, I am satisfied numerous citizens of
Gibeon are involved—in the distribution and marketing of the liquor. I
am quite certain, for instance, that the business of taking
photographs is not the sole means of livelihood followed by Lancelot
Bangs.... He is, I believe, a cousin to the proprietor of the Lakeside
Hotel.... These things are present in the compound, but they could
not, joined together, cause the result we see. The principal ingredient
is missing.”
“And what is that?”
“A daring, ruthless intelligence. Able leadership. The brain capable of
conceiving of bootlegging as an industry, and not as a matter of petty
retailing.”
Carmel Lee was impressed. Evan Pell possessed the quality of
holding interest, of seeming to speak from sure knowledge.
“I think you are right so far. What we need is to find this intelligence.”
“I rather fancy I have found him. In fact, I have had little doubt as to
his identity for a considerable time.”
“Abner Fownes?” She shrugged her shoulders. “I dislike him—he is
insufferable—but the idea is absurd. Bumptious little men like him,
secure in their wealth and position, do not jeopardize it.”
“That,” said Evan, “is dependent upon their security. What would you
say if I were to tell you Abner Fownes has been on the brink of
bankruptcy for months? What would you say if I told you this rum
running commenced only after his finances became tangled? What
would you say if I told you the major part of the profits from this liquor
business went to maintain Abner Fownes in the character he has
assumed, and keep his imperiled business out of the hands of his
creditors?”
“I would say,” she said, “that you are crazy.”
“Nevertheless,” he said, “I am convinced of the fact.”
“But he has no brains. Look at him. Observe him.”
“Miss Lee, it takes a man of tremendous resolution and of very keen
intelligence to invent for himself a character such as he has exhibited
to Gibeon for years.... If the world supposes you are a nincompoop—
a vain figurehead—a puppet set up by other men—you are little in
danger of arousing suspicion as to yourself. When a man is
commonly admitted to be a fool, he is safe. Fownes has been at
infinite pains to prove himself a fool.”
Carmel was far from dull. Her mind flashed to the keystone of the
arch Pell was constructing. “Show me he is on the verge of
bankruptcy and maybe you can convince me of the rest.”
He told her. He itemized the contracts Fownes had made for the
purchase of lumber, and the prices at the time of sale. He showed
how the market had declined, and the total sum of Fownes’s losses.
“These,” he said, “are facts—not public, but easy to come by.... I first
found the trail of them when the cashier of the bank asked me to
assist him in an audit of the books. That was some months ago
when I occupied my official position.”
“But if you are right, then Abner Fownes is a murderer, or an
instigator of murder.... Nobody can look at him and credit that.”
“Abner Fownes,” said Pell, “is capable of any crime to preserve
Abner Fownes. I have watched him, studied him. I know.”
“I can’t believe.... It is incredible. No. You must be mistaken.”
“Miss Lee,” said Pell, solemnly, “if you wish to continue to exist, if
you hope to come through this affair with your bare life, you must
believe. If you cannot believe, pretend it is a fact and act accordingly.
Forget everything else and concentrate upon Abner Fownes.... But
take this warning: The moment he suspects you suspect him—you
will doubtless join Sheriff Churchill.... I believe Churchill was on the
road to the discovery. He would not have disappeared otherwise.”
Carmel remained silent, considering. At length she spoke. “You are
right,” she said. “One does not insure his house because he believes
it will burn, but in case it shall burn. I shall make believe you are right
about Abner Fownes—as an insurance policy.... But where does that
lead us?”
“To the sheriff’s office,” said Pell.
“What?”
“If Jenney is appointed sheriff to succeed Churchill, where is the
machinery to fight Fownes? He could laugh at us. Therefore Jenney
must not be appointed.”
“But how can that be averted?”
“I think,” he said, “the sole hope lies in yourself.”
“In me!”
“You must find a man, a man of courage, of public spirit. You must
find a man who can be relied upon and whose name will carry weight
with the Governor.... When you find him, you must go to the Capitol
and make the Governor appoint him—and you must act at once.”
“I?... I go to the Governor?”
“You.... If you could carry a petition, signed by a number of citizens, it
would strengthen you, but I don’t see how that can be done.... And
yet—and yet——”
“It must be done.... Secretly.”
“To approach one man—who would talk, who was on the other side
—would be to ruin the whole project.”
“Nevertheless, it must be done.”
He shrugged his shoulders. “First find a man worthy to hold the
office,” he said.
“I shall find him.... I know Mrs. Churchill. She will know her
husband’s friends and supporters—the men who worked for his
election and whom he trusted.”
“The idea is good,” said Evan. “Suppose you act without delay.”
Carmel found Mrs. Churchill in the kitchen, giving a hearty welcome,
in spite of her baking, to the visitor.
“Set,” said Mrs. Churchill, “and lemme pour you a cup of tea. Always
keep it simmerin’ on the back of the stove in case of headache.” This
was a favorite fiction of Mrs. Churchill’s—that she suffered with her
head and that tea was the only remedy. It would appear, however,
that she used the beverage as a preventive instead of a cure.
“I’m sorry, but I haven’t time to sit this morning. I’ve come to you
because you’re the only person in Gibeon who can help me—and
because you are the one most interested in helping me.... I want to
know whom to trust.”
“Eh?... Trust? Speakin’ of young men, be ye?”
“No.” Carmel smiled as she saw the fire of matchmaking light Mrs.
Churchill’s motherly eyes. “I want to know whom your husband
trusted. I’ve got to find a man.... Deputy Jenney is going to be
appointed sheriff,” she said.
Mrs. Churchill’s eyes flashed. “In my man’s place! That critter!”
“If,” said Carmel, “I can’t find an honest man—one like your husband
—and get there first.”
“Uh huh....” said Mrs. Churchill, ruminatively. “He wa’n’t much give’ to
talkin’, but more’n once he says to me, says he, ‘The’ hain’t many in
this place I’d trust as fur’s I could throw ’em by the horns,’ he says.
But I call to mind that whenever he got kind of out of his depth like,
and had to talk things over with somebody, he allus went to spend
the evenin’ with Jared Whitefield. Him and Jared was close. I don’t
calc’late you’d make no mistake goin’ to Jared and statin’ your case.”
“Thank you,” said Carmel. “There’s not a moment to be wasted.
Good-by.”
She did not return to the office, but walked out the main street, past
the village cemetery, to the rambling, winged house from which
Jared Whitefield ruled his thousand-acre stock farm—a farm he had
carved himself out of the forest, cleared, stumped, and planted. She
knew the man by sight, but had never held conversation with him. He
was not an individual to her, but a name. She opened the gate with
trepidation, not because she feared the reception of herself, but
because she was apprehensive. Mr. Whitefield, when studied at
close range, would not measure up to the stature of the man she felt
was needed.
A dog barked. A voice silenced the dog. Carmel noted how suddenly
the dog quieted when the voice spoke. Then a man appeared
around the corner of the house, an ax in his hand, and stood
regarding her. He did not bow, nor did he speak. He merely stood,
immobile, as if some cataclysm of nature had caused him to burst
through the soil at that spot, and as if there still remained embedded
roots of him which anchored him forever to the spot. He was big,
straight, bearded. At first glance she thought him grim, but instantly
decided it was not grimness, but granite immobility. She approached
and greeted him.
“Good morning, Mr. Whitefield,” she said.
He inclined his head and waited.
“I am Miss Lee, proprietor of the Free Press,” she said.
“I know ye,” he said.
Surely he was difficult; but for all that, she felt herself drawn to the
man. There was a feeling that if she could scale his granite sides
and sit upon the shelf of his shoulder she would be safe—that
nothing could topple him from the spot where he had taken root.
“I want to talk to you, Mr. Whitefield. It is a matter of great importance
—almost of life and death,” she said.
“Say it,” said Jared Whitefield.
“They’re going to appoint Deputy Jenney sheriff,” she said.
“Know it.”
“It mustn’t be.”
“Why?”
“Is it safe to speak here. A word overhead——”
“This is my yard,” said Jared, and there was much, much more in the
words than the mere statement of the fact. It was a declaration of
independence. It was a guaranty. It lifted Jared out of the
commonplace and made a personage of him—the unquestioned
ruler of a principality. Where he was, he ruled.
“You know what my paper has done.”
“Lighted matches nigh a powder keg.”
“I believe, and I hope to prove, there is an organization here for the
purpose of wholesale dealing in smuggled liquor. I believe that
organization murdered Sheriff Churchill. I believe Jenney is a part of
it and that his appointment as sheriff is a move to give the criminals
safety in their work. I know there are huge profits. At the top is some
man of intelligence who directs. I want to get that man.”
“Who?”
“I think Sheriff Churchill knew—or guessed. That’s why he is dead.”
“Uh!... Wa-al?”
“Our only chance is to block Jenney’s appointment. To get first to the
Governor with the name of another man—a man whose name and
personality carry weight. If we can get the office of sheriff we are
halfway to success.”
“Will Abner Fownes back the man you pick? Go to the Governor fer
ye?”
She looked at him briefly, moved a step closer, and lowered her
voice.
“Abner Fownes,” she said, “is the man I believe to be the chief of the
rum runners. I believe he gave the word to kill Sheriff Churchill.”
Whitefield moved for the first time. He ran a hand through his beard
and drew a breath like a sigh.
“Life insured?” he asked.
“You will be my life insurance.”
She took him by surprise; his features actually changed for an
instant. “Me?” he said.
“When you are sheriff,” she said.
“I’m fifty. By mindin’ my business I got twenty-odd year to live.”
“He was your friend,” she said.
There was a long silence while she watched his face, and he,
looking over the top of her head, stared at the field and woodland
stretching to the horizon.
“He was my friend,” said Jared Whitefield.
“Then you will?”
“Can’t be done. Fownes has the say.”
“I think it can be done. Will you let me try?”
He considered in his ponderous way. Then he turned without a word
and walked away. He proceeded half a dozen steps and then halted.
“Yes,” he said, over his shoulder, and continued on his way.
CHAPTER XVII
CARMEL walked back rapidly, but her pace did not interfere with the
activities of her mind. She had many things to reflect upon, and not
the least of these was a sudden realization that Evan Bartholomew
Pell had, of a sudden, as it were, taken command. It was he, rather
than herself, who had risen to the emergency. He had seen the
necessities of the situation. He had comprehended the situation itself
as she had never done. While she had been obeying impulse he had
been acting intelligently. It was true he seemed to have little tangible
evidence to work upon, but, somehow, she felt he would be able to
find it. The amazing thing was that, without effort, without seeming to
do so, he had moved her into secondary place. He had told her what
to do, and she had done it without question.... Evan was a surprising
person, a person of submerged potentialities. She wondered just
what kind of man he would be if he ever came to himself and came
into his own personality. In addition to which, Carmel, like all other
women, could not but give careful consideration to a man who had
declared his love for her.
Then there was Jared Whitefield to appraise. She liked him, but
found herself somewhat in awe of his granite impassivity. She felt he
had looked through and through her, while she had not been able to
penetrate the surface of him. She had talked; he had listened. He
had made his decision, and wholly without reference to herself, or to
what she had said to him. But, on the other hand, he seemed to
have washed his hands of the responsibility for his appointment as
sheriff. If it could be managed—well and good. He would serve. But
that seemed to be all. He offered no assistance, no suggestion. He
had said “Yes” and walked out of the boundaries of the matter.
Jared Whitefield was a personality, of that she was certain. He was a
man to impress men, a man to rule, a man never to be overlooked....
Why, she wondered, had he remained inactive in Gibeon. Apparently
he had rested like a block of granite beside a busy thoroughfare,
negligent of the bustle of passing traffic. What, she wondered, did
Gibeon think of Jared. How would he appeal to Gibeon as its
candidate for sheriff?
She reached the office and found Evan Pell waiting for her.
“Well?” he said.
“I’ve found the man, and he has agreed to serve.”
“What man?”
“Jared Whitefield.”
He nodded, almost as if he had known it from the beginning. It
irritated her.
“You’re not surprised at all,” she said sharply.
“No.”
“Why?”
“Because it would have required colossal stupidity to choose any
other man—and you are not stupid.”
She looked at Evan with curiosity, and he sustained her gaze. He
was changed. She saw that he had been changing through the days
and weeks, gradually, but now he seemed to have made some great
stride and reached a destination. He did not look the same. His face
was no longer the face of an egoistic pedant. It was not alone the
laying aside of his great, round spectacles. The thing lay rather in his
expression and in his bearing. He seemed more human. He seemed
larger.... She was embarrassed.
“The petition,” she said. “I must have that.”
“Signatures would be easy to get. There are a hundred men who
would sign any petition with Jared Whitefield’s name on it. Men of
standing. But to approach one man who would go to Abner Fownes
with the story—well——” he shrugged his shoulders. “I don’t
suppose one man in a hundred realizes what is going on under the
surface in Gibeon.”
“We must take the risk.”
“I’ll prepare the petitions and have Tubal print them—at once.”
She sat down at her desk and wrote a moment, then got up and
walked with steady steps into the composing room. Evan Pell stood
looking after her with a queer expression; it was a look of loneliness,
of yearning, of self-distrust, of humility. He was thinking about Evan
Pell and of what a failure he had made in the handling of his life. He
was considering how little he knew, he who had fancied himself of
the wisest. He weighed the value of book knowledge against the
value of heart knowledge, and found himself poverty-stricken.... It
seemed so hopeless now to turn himself into the sort of man he
wanted to be; the sort of man he had come to comprehend it was
worth his while to be.
“I never would have found it out,” he said to himself, “if I had not
loved her.”
The door opened stealthily and a barefoot urchin entered whose
clothing consisted of trousers many sizes too large and a shirt so
dirty and torn as not to resemble a garment at all. He glared at Evan
and snarled:
“Where’s she?”
“Where’s who?” said Pell.
“The editin’ woman.”
“What do you want of her?”
“None of your business.... Hey, leggo of me, damn you! I’ll bite ye!
Leggo!”
Pell had the child by the nape of the neck and held him so he could
not escape. He noticed a paper crumpled in one grimy hand and
forced the fingers open. It fell to the floor, and as he reached for it
the boy wriggled free and darted out to the sidewalk, where he
grimaced horribly and twiddled his fingers at his nose. “Ya-aaa-ah!”
he squealed, and fled down the street.
Pell smoothed out the paper and read, in cramped, printed letters.
They hain’t treated me square and I’m getting even.
They’re fetching it in to-night. Truckloads. You can git
evidence at the Lakeside. Eleven o’clock.
That was all, no signature, nothing to indicate the identity of the
writer. Evan folded the paper and thrust it into his vest pocket. He
looked through the door of the composing room and frowned. The
line of his mouth was straight and narrow. Eleven o’clock, at the
Lakeside Hotel!... Queerly enough, the thought flashed into his mind.
What drew Sheriff Churchill out of his house on the night of his
disappearance?... Evan passed through the swinging gate and sat
down at his table just as Carmel re-entered the room.
“Who was in?” she asked.
“Nobody,” said Evan Pell. “Just a kid asking for blotters.”
She would go to the Lakeside Hotel. It was not in her character to do
otherwise. She would go, she would place herself in peril. Had the
note come into her hands, he had no doubt she would have
concealed it and have gone alone.... Well, she did not receive it. She
would not go. That much was sure.
Carmel spoke. “There goes Abner Fownes,” she said, and, turning,
he saw the well-known equipage with the coachman on the front
seat and Fownes, pompous, making a public spectacle for the
benefit of an admiring public, bolt upright in the rear seat.
“He’s going some place,” said Carmel. “See. He has a bag.”
“Yes,” said Pell. He remembered that Fownes had been absent from
Gibeon on the night Churchill had disappeared. “Yes, he’s going
some place.”
They watched the equipage until it disappeared, making the turn
toward the railroad station.
“Tubal will have the petitions in ten minutes,” she said. “How will we
go about getting signatures?”
“I don’t think that matters,” he said, absently.
“What?”
“I—I beg your pardon.... Er—signatures. Of course. Signatures.”
“What ails you, Mr. Pell. Of course, signatures. We weren’t speaking
of potatoes.”
His manner was strange, she thought. He seemed a trifle pale. Was
he ill?... No, he said, he was not ill, he was afraid he had been a trifle
absent-minded. Carmel eyed him sharply. The thing did not look like
absent-mindedness to her.
He arose and went to the telephone. “Give me the station, please,”
he said, and then waited. “Is this the station? This is the Free
Press.... Yes.... No news? Um!... Just saw Mr. Fownes going past
with a bag. Thought he might be going away. We like to print
something when people go away.... Bought his ticket?... To the
capital, eh?... Thank you.” He hung up the receiver, and there was a
look of profound relief on his face. This was surprising to Carmel.
Why he should be relieved by learning Fownes was on his way to
the capital was beyond her comprehension.
“Miss Lee,” he said, “there will be no time to get signers to a
petition.”
“Why?”
“Because you must start at once for the capital.”
“But the train is leaving. It will be gone before I can get to the depot.”
“Abner Fownes is going to see the Governor,” he said. “There can be
but one reason for it. He has decided he needs a sheriff. He’s
gone.... It is a six-hour trip by rail, with the change at Litchfield.”
“What of it?”
“By automobile one can make it in five hours—or less.”
“But——”
“If you will go to your hotel, please, and dress and pack a bag, I will
have a car waiting for you here.”
She frowned. This was giving orders with a vengeance.
“I’m still owner of this paper,” she said.
“Please, Miss Lee,” he said, and there was humility, pleading in his
voice. “Don’t be unreasonable now. This must be done. Nobody can
do it but you. Please, please make haste.”
She did not want to obey. It was her desire to rebel, to put him once
for all in his old subordinate place, but she found herself on her feet
in obedience. He compelled her. He had power to force her
obedience. She was amazed, angered.
“I shan’t——” she began, in a final effort to mutiny.
“Miss Lee,” he said, gravely, gently, and she was touched and
perplexed by the gentleness of his voice, “you have spoken to me of
service, of forgetting oneself to be of service to others.... Please
forget yourself now. You are not doing this for me or for yourself.... It
is necessary.... I beg of you to make haste.”
There could be no refusal. She passed through the gate and found
herself walking with rapid, almost unladylike strides, to the hotel. Up
the stairs she rushed and into her room. In five minutes she was
redressed in a gray tailored suit. Then she set about packing her
bag, and, singularly enough, the first thing she put into it was an
evening gown, the gown which she had worn but once, and that to
the final ball at the time of her graduation. Why she included this
dress she could not have said, unless feminine vanity were at work
—a hope that an opportunity to wear it might present itself.
In fifteen minutes she re-entered the Free Press office. A touring car
stood at the door, with a young man, strange to her, behind the
wheel.
“I’m ready,” she said to Evan Pell.
“Thank you,” he said, quietly. Then: “Don’t let anything prevent you
from coming to the Governor. You will know what to say. See him
before Abner Fownes gets his ear ... and ... and come back safely.”
His voice dropped, became very low and yearning, as he spoke
these final words. “Come back safely—and—try not to think of me as
—harshly as you have done.”
“I—have never thought of you harshly,” she said, affected by his
manner.
He smiled. “I am very glad I have loved you,” he said. “Will you
please remember I said that, and that it came from my heart.... It is
the one fine thing which has come into my life.... It might have
changed me—made me more as you would—less the man you have
criticized.”
“Why, Mr. Pell!... You speak as if I were never to see you again. I
shan’t be gone more than a day.”
He smiled, and there came a day not far distant when she
remembered that smile, when it haunted her, accused her—and
gave her a strange happiness.
“One never knows,” he said, and held out his hand. She placed her
hand in his, and then he performed an act so out of tune with Evan
Pell, pedant and egoist, that Carmel gasped. He lifted her hand to
his lips. The gesture was not artificial, not funny. There was a grave
dignity, a sincerity in the act which made it seem quite the right thing
to have done. “Good-by,” he said. “You are very lovely.... Please
make haste....”
He helped her into the car, and she turned. “Mr. Pell——” she said,
but he was gone, had returned to the office and was invisible.
“Ready, miss?” the driver asked.
“You know where you are to go?”
“Yes, miss.”
“Whose car is this?”
“Mr. Whitefield’s,” said the driver, as he threw in his gear and the
machine moved up the street.
Carmel’s mind was not on the car, nor on its destination, nor upon
her errand. It was upon Bartholomew Pell.... Could she have seen
him seated before his table, could she have read his thoughts, have
comprehended the expression of happiness upon his face, she
would have thought even more urgently of him.... For he was saying
to himself: “Thank God she’s out of it. She’s safe. I’ve done that
much, anyhow.”
He drew the mysterious note from his pocket and studied it
attentively. “She would have gone,” he said, “so I shall go....
Doubtless it is a trap of some sort—but it may not be.... And she is
safe—she is safe.”
CHAPTER XVIII
CARMEL wondered how one went about it to obtain a private
interview with a Governor. She was still young enough and
inexperienced enough in life’s valuations to regard a man in that
position as necessarily above the ordinary run of men. His office
invested him with a certain glamour, a fictitious greatness.
Governors, Senators, Presidents! Youth invested them with a terrific
dignity. It is somewhat difficult, even for the wise and prudent, to see
the man apart from his vestments; to understand that there is, in
reality, very slight difference between human beings, and to
approach those in authority with the sure knowledge that, no matter
how lofty their position, they have, at best, but two arms and two
legs, a fondness for mince pies, and a failing for colds in the nose.
Governors quarrel with their wives, and have ingrowing toe nails.
The forty-eight of them, heads of the several states of the Union,
remind one of the main street in a boom town—two stories on the
sidewalk, but a ramshackle shed in the rear....
No sooner did the dome of the Capitol appear through a break in the
wheels than Carmel began to dress herself mentally for the meeting.
She had a horrible fear she would become tongue-tied and thrust her
thumb in her mouth like an embarrassed little girl who has forgotten
her piece.... She glanced at her watch. It was five o’clock.
How late did Governors work at governing?... She directed her
chauffeur to drive to the Capitol, and there she alighted because she
had no idea what else to do. She climbed the imposing steps and
entered the building. It was a repellent sort of place; a mausoleum of
assassinated ambitions, and it chilled her. The corridors were all but
deserted.
Leaning against a column adjacent to a brass cuspidor was an old
man in a uniform which might have been that of a prison guard, a
janitor, or a retired street car conductor. Carmel approached him.
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!

textbookfull.com

You might also like