C# Best Practices: Collections and Generics

This course covers best practices for using C# collections and generics, guiding you on the path from apprentice, to skilled C# software developer.
Course info
Rating
(572)
Level
Beginner
Updated
Jan 27, 2016
Duration
3h 35m
Table of contents
Course Overview
Introduction
Arrays
Building Generic Code with Generics
Generic Lists
Generic Dictionaries
Generic Collection Interfaces
LINQ
Final Words
Description
Course info
Rating
(572)
Level
Beginner
Updated
Jan 27, 2016
Duration
3h 35m
Description

When building applications we often deal with groups of things: a user's preferences, a customer's orders, or a product's color choices. To implement these groups of things in C#, we use collections. And to get the most from collections, we need to leverage generics. This course covers how, when, why, and best practices for using C# collections and generics, including arrays, generic interfaces, LINQ, delegates, and Lambda expressions.

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: Collections and Generics from Pluralsight. Aw, Generics. That challenging to explain topic that often shows up even in the most basic of beginner courses because without generics, we don't have a good way to work with collections of things and most applications require working with collections of things. In this course, we start with a classic collection type, arrays. We then jump into generics covering what they are and how we can leverage them to build more generic or generalized code. With that, we'll have the basics we need to tackle generic lists and generic dictionaries. Then we'll dive deeper into generic collections and look at the interfaces that they implement. We'll see how to leverage those interfaces as method parameters and method return types. Lastly, we'll look at Language Integrated Query, or LINQ, for our filtering, shaping, ordering, grouping, aggregating, or locating elements in a collection. By the end of this course you will know the how, when, why, and best practices for working with C# collections. I hope you'll join me on this journey through C# Best Practices: Collections, and Generics from Pluralsight.

Arrays
Arrays are a fundamental feature of many programming languages, including C#. We can use arrays to manage collections of things such as a set of color choices. Welcome back to C# Best Practices: Collections and Generics from Pluralsight. My name is Deborah Kurata, and this module covers best practices for defining and using arrays. An array is a fixed-size list of elements that can be accessed using a positional index number. For example, here is an array of color choices and here is an array of product objects. In C#, the index is zero-based meaning that the first element in an array has an index number of 0. Unlike other types of lists, arrays are fixed-size. That means that we must define the desired size of the array when we initialize it, and once initialized, we can't adjust that size. In this module, we'll evaluate different ways to initialize an array. We'll start with basic declaration and population, then use collection initializers to reduce the number of lines of code. We'll look at how to retrieve an element from an array and iterate through all of the elements of an array. We'll try out some of the static and instance methods available when working with arrays. These methods provide features such copying or sorting an array. 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.

Building Generic Code with Generics
Generics are a powerful feature that allow us to write more reusable code, and many of the built-in C# collection classes use generics to provide type-safe collections. Welcome back to C# Best Practices: Collections and Generics from Pluralsight. My name is Deborah Kurata, and this module covers the what, why, when, and best practices for building generic classes, generic properties, and generic methods. Generics are a technique for writing code without specifying data types and yet still providing type-safety, which means everything has a data type and the compiler validates those types while compiling. Generics are a way to make our code, well, more generic. In this module, we'll discover what all of this means. We'll start with a demo to build the case for generics. Then we'll build a generic class and demonstrate how we can write more reusable code with generics. Next, we'll see how to use a generic class including how to strongly-type an instance of the generic class. We'll cover generic methods and see how to leverage generics for the method return type or any of the method parameters and we'll briefly look at the more advanced topic of generic constraints. 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.

Final Words
As you have seen throughout this course, there is more to learning C# than just the fundamentals. It is important to understand the when, why, and best practices. Welcome back to C# Best Practices: Collections and Generics from Pluralsight. My name is Deborah Kurata, and the final words in this course include some takeaways and a few pointers to additional information. Let's jump right into this short module.