C# Best Practices: Improving on the Basics

This course covers best practices for using basic C# features, guiding you on the path from apprentice to skilled C# software developer.
Course info
Rating
(1297)
Level
Beginner
Updated
Oct 29, 2015
Duration
4h 50m
Table of contents
Course Overview
Introduction
Defining Proper Classes
Building Good Classes
Accessing and Using Classes
Defining Fields Appropriately
Creating Good Properties
Creating Good Methods
Specifying Clear Method Parameters
Handling Strings
Final Words
Description
Course info
Rating
(1297)
Level
Beginner
Updated
Oct 29, 2015
Duration
4h 50m
Description

Once you learn the fundamentals of C#, (the basic syntax and control flow) where do you go from there? If you were learning carpentry, there would be a step between learning how to use a saw and building a house. That step is called an apprenticeship. Think of this course as your apprenticeship. This course covers best practices for using basic C# features, guiding you on the path from apprentice to skilled C# software developer.

About the author
About the author

Deborah Kurata is a software developer, consultant, Pluralsight author, Google Developer Expert (GDE) and Microsoft Most Valuable Professional (MVP). Follow her on twitter: @deborahkurata

More from the author
Angular: Getting Started
Beginner
5h 41m
Nov 8, 2018
Angular Reactive Forms
Intermediate
3h 52m
Nov 6, 2018
Angular NgRx: Getting Started
Beginner
4h 4m
Jun 25, 2018
More courses by Deborah Kurata
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hello. My name is Deborah Kurata, and I'd like to welcome you to my course, C# Best Practices: Improving on the Basics, from Pluralsight. When I first started out in my software development career, I quickly learned that there is a big difference between knowing how to write code and how to write code well, and therein lies the challenge. Once you learn the fundamentals of C#, where do you go from there? If you are learning carpentry, there would be a step between learning how to use a saw and building a well-designed and constructed house. That step is called an apprenticeship. Think of this course as your apprenticeship. In this course, we cover the how. How to build good classes, fields, properties, and methods, and how to use new C# 6 features such as the null conditional operator and string interpolation. It covers the when, including when to use static classes, singletons, lazy loading, and expression bodied members. It defines the why, such as why use method overloading or method overriding? And, it covers best practices for using the basic C# features. These topics guide you on the path from apprentice to skilled C# developer. From here you can continue your learning with these other Pluralsight courses: C# Best Practices: Collections and Generics, Object-Oriented Programming Fundamentals in C#, and Defensive Coding in C#. I hope you'll join me on this journey through C# Best Practices: Improving on the Basics, from Pluralsight.

Defining Proper Classes
Defining proper classes in the appropriate layer of an application can be a challenge. Following best practices when defining classes helps us put appropriate code in appropriate places, making development, debugging, testing, and maintenance easier. Welcome back to C# Best Practices: Improving on the Basics from Pluralsight. My name is Deborah Kurata, and this module covers best practices for defining C# classes. The focus of this course is on basic C# language features, but to talk about best practices, we need to put those language features into context. Laying out the application architecture will give us that context, and provide the foundation for our application. We'll come back to this architecture shortly. First, let's outline what we will cover in this module. This module lays the foundation for this course. We'll start with an overview of basic C# application architecture to provide the big picture view of a C# application. Next we'll define what a class is. We'll look at the different types of classes we can create, UI classes, domain classes, and so on. Then, we'll take a brief look at unit testing. Any course on C# best practices would be incomplete without unit testing. We'll use unit tests throughout this course to run the code we write. We'll conclude with a set of frequently asked questions. These are the types of questions that you may see in a C# programming interview. Let's start with a look at a common C# application architecture to put classes into context.

Building Good Classes
Classes hold most of the code for our application. Following best practices when building classes helps us get more from our classes; more quality, more reusability, and more maintainability. Welcome back to C# Best Practices: Improving on the Basics from Pluralsight. My name is Deborah Kurata and this module covers best practices for building good C# classes. The code we write for a class includes the class signature, defining the class name and accessibility, fields, properties, methods, and constructors. Adding one more term here, together these are often referred to as members. So the phrase class members refers to all of the fields, properties, and methods of the class. In this module, we'll build a class, examining the code, and considering best practices. We'll define a set of constructors for the class, and we'll take a look at namespaces. Next we'll build a static class and see how it is different from a non-static class. We'll look at what a singleton is and how to define one. We'll conclude with a set of frequently asked questions. These are the types of questions that you may see in a C# programming interview. Let's get started.

Defining Fields Appropriately
Fields hold the data in our application, so defining fields appropriately helps ensure that data is correctly identified and retained. Welcome back to C# Best Practices: Improving on the Basics from Pluralsight. My name is Deborah Kurata, and this module covers best practices for defining fields in our classes. Fields can be variables or constants, read-only or read-write, public or private, built-in types or types defined by the classes we write. In this module, we'll start with a more detailed look at backing fields and introduce nullable types. We'll cover constants and read-only fields. Then, we'll compare and contrast constant and read-only, and conclude with a set of frequently asked questions. These are the types of questions you may see in a C# programming interview. Let's get started.

Creating Good Properties
Creating good properties is about more than just encapsulating our fields. We want to write good code in our setters and getters, define appropriate accessibility, and use properties wisely. Welcome back to C# Best Practices: Improving on the Basics from Pluralsight. My name is Deborah Kurata, and this module covers best practices for creating good properties in our classes. Properties are simply getter and setter functions that can be used to guard access to the fields of a class. They encapsulate the fields, providing better control over the data contained in the field. Okay, we've said that properties guard fields several times so far in this course, but I'm just not seeing that here. How is this property protecting this field? As it is written, it really isn't. Any code can call the getter to get this field or call the setter to set this field. What are we missing here? Well, one thing that we're missing is some code. We can put code in the getter and setter to actually protect and validate the field. In this module, we'll start by adding code to our properties. Then we'll see how to use auto-implemented properties, which will save us time and effort. We'll cover property accessibility modifiers and look at additional uses of properties. Next we'll introduce expression-bodied properties, which are new in C# 6. Then we'll identify the benefits of using properties, and we'll conclude with a set of frequently asked questions. These are the types of questions you may see in a C# programming interview. Let's get started.

Final Words
As you have seen throughout this course, there is more to learning C# than just the fundamentals. It's important to understand the when, why, and best practices. Welcome back to C# Best Practices: Improving on the Basics from Pluralsight. My name is Deborah Kurata, and the final words in this course include a look at clean code, a brief review, and pointers to additional information. Let's jump right in to this short module.