Discover Programming with C#
Discover Programming with C#
Featuring .NET Core 3 & C# 8
About the Book
This is a book for those who are interested in learning how to program. It introduces C#, a modern object-oriented, cross-platform language that is used extensively in business and web applications. It provides a robust library of functionality that increases cross-platform capabilities and prevents programmers from constantly having to implement basic and advanced functionality from networking to I/O operations to security functions. C# and .NET have a vibrant developer community and are commercially supported by Microsoft.
I have been programming C# since its public release in early 2002. I have used it for web development, system administration, and database applications. I have used it in the educational, financial, telecom, warehouse management, and procurement sectors. C# is not the first language I learned to program, but it has been my most productive.
This book does not start out with the reader copying text into a text editor. It begins with a thorough foundation of the basics of programming C#. Many programmers that I interview today do not know the foundational basics required to be great C# programmers. The typical pattern for learning C# in recent years has been to code first and ask questions later. These questions are rarely asked and often lead to poor quality software.
This book does make some generalizations and does not cover every aspect of the C# language such as bitwise operations. It provides the reader with the amount of information I feel is relevant to creating a good programmer. There are many great resources available for learning about the history of computing, design patterns, refactoring, object-oriented programming, Entity Framework, and ASP.NET MVC. This book prepares you to understand those books.
I hope this book is helpful to all those who read it. I taught myself to program and hope to help you do the same.
The Author
Table of Contents
- Pre-release Notes
- Introduction
- A Word to the Reader
- Code License
- Some Definitions
-
1. Milestones
- 1.1 Early Systems
- 1.2 The Next Generation
- 1.3 Higher Level Languages
- 1.4 What’s in an Operating System?
- 1.5 C Follows B and So Goes the World
-
2. First Things First
- 2.1 Runtimes
- 2.2 Frameworks
- 2.3 .NET Standard
- 2.4 .NET 5
- 2.5 Starting Out
- 2.6 Variables
- 2.7 A Bit about Bits
- 2.8 Scalars
- 2.9 Math Operators
-
3. Strings
- 3.1 Garbage Collection
- 3.2 Sorting and Encoding Strings
- 3.3 Creating a String
- 3.4 @ Character
- 3.5 Character Literals
- 3.6 Nullable Types
-
4. Array Basics
- 4.1 Definition
- 4.2 Single-dimensional Arrays
- 4.3 Multidimensional Arrays
- 4.4 Jagged Arrays
-
5. Logic and Control Structures
- 5.1 Boolean Logic or Black & White
-
5.2
if
Statements - 5.3 Short-circuit Operators
- 5.4 Other Operators
-
6. More Logic and Control Structures
- 6.1 Conditional Access Operators
- 6.2 Null Coalescing Operator
- 6.3 Basic Switch Statement Usage
-
6.4 The Dreaded
goto
Statement - 6.5 Iteration and Loops
-
6.6
break
andcontinue
-
6.7
for
- 6.8 Variable Scoping: The Basics
- 6.9 foreach
-
6.10 The
var
Keyword
-
7. Objects and Classes, Part 1
- 7.1 The Four Principles of OOP
-
7.2 What’s in a
namespace
? - 7.3 Classes and Their Members
- 7.4 Static vs. Instance Members
- 7.5 Fields (Static and Instance)
- 7.6 Methods (Static and Instance)
- 7.7 Pass by Value vs. Pass by Reference
- 7.8 The Difference Between Reference and Value Types
- 7.9 Passing Reference Types By Reference
- 7.10 Out Parameters
-
7.11 The
params
Array - 7.12 Optional Parameters
- 7.13 Named Parameters
- 7.14 Chaining Methods
- 7.15 Extension Methods
- 7.16 Method Overloading
- 7.17 Properties (Static and Instance)
-
8. Objects and Classes, Part 2
- 8.1 Access Modifiers and Accessibility Types
- 8.2 Constructors (Static and Instance)
- 8.3 Static Constructors
- 8.4 Expression-bodied Members
-
9. Exceptions
- 9.1 A Brief Introduction to Inheritance
- 9.2 Handling Exceptions
- 9.3 An Example and Three Questions
-
9.4
throw
Your Own - 9.5 Another Example
-
10. Objects and Classes, Part 3
- 10.1 Operators (Instance)
- 10.2 Type Casting and Boxing/Unboxing
- 10.3 Implementing Type Conversions
- 10.4 Indexers (Instance)
- 10.5 Events (Instance)
- 10.6 Finalizers (Instance)
- 10.7 Nested Types (Static and Instance)
-
11. Object Inheritance and Interfaces
- 11.1 A Better Example
- 11.2 A Little Polymorphism
- 11.3 Sealed
- 11.4 Abstract Classes and Members
- 11.5 Interfaces
- 11.6 Overriding Sealed Members
- 11.7 Coming Full Circle
- 11.8 Providing a Default Implementation
-
12. Creating Value Types
- 12.1 Enumerations
- 12.2 Flags
- 12.3 String Library
- 12.4 Structs
- 12.5 Equals and GetHashCode
- 12.6 Useful Framework Structs
-
13. Using Generics
- 13.1 What is a generic?
-
13.2
List<T>
- 13.3 Rant on a Tangent
-
13.4 Back to
List<T>
- 13.5 Sorting a List
-
13.6
Dictionary<TKey, TValue>
-
14. Creating Generics
- 14.1 Lambdas and Delegates
- 14.2 Action<T>
- 14.3 Func<T, TResult>
- 14.4 Generic Methods
- 14.5 Generic Type Constraints
- 14.6 A Real Example
- 14.7 Recursive Methods
- 14.8 Continuing with Our Example
-
15. Fluent APIs and LINQ
- 15.1 Fluent APIs
- 15.2 LINQ, Lamba-style
-
16. Miscellaneous Language Features
- 16.1 ValueTuple
- 16.2 ?
- 17. Basic I/O
- 18. Reflection
- Visual Studio Quickstart - Windows
-
Reusable .NET Components
- Frameworks on Frameworks
- NuGet
-
C# Version History
- Prognostication
- Recommended Reading
- My Personal Coding Style
- Legal Matter
- Colophon
- About the Author
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them