
Explore .NET generics to reduce code duplication, enforce compile-time type safety, and eliminate boxing and unboxing, from generic collections to creating your own generic types, with C# and VB.NET examples.
Meet the author, a self-employed dot net veteran since 1987, skilled in C# web and desktop development, with roots in Delphi and Clipper, now providing consulting.
Explore the tools used in this course, including Visual Studio versions 2013, 2012, and 2015, NuGet for package restore, and unit testing framework with fluid assertions for readable unit tests.
Explore generics in .NET, covering generic methods, classes, interfaces, delegates, and inheritance with generics, plus constraints, framework types, real-world transformations from non-generic to generic code, and a linked list example.
Learn to implement a generic method in .NET by creating a by-reference swap with type T, tested with int and string; see generic methods can be static or extension methods.
Explore generic classes with a type parameter T, using a list-backed repository to add, delete, and get items, and examine complex types and method scope with person and book.
Explore inheritance and generics with an abstract base class, a non-generic child that specifies an explicit type, and generic children that pass through base types like diagram and schema.
Learn how to declare generic delegates and events, wire up a Shape class display event, and compare custom delegates with built-in Action and Func for flexible event handling.
Explore how generic default values work in .NET by examining a simple generic list, default(T), and how values differ for objects, ints, and structs.
Explore type inference in generic methods, learning when the compiler deduces T from arguments in swap and when it must infer from a return value in serialise.
Explore nested generic definitions in .NET, including using IEnumerable of delegates and alias techniques to simplify complex generic syntax, with practical tests validating a person's first and last name.
Explore VB.NET generic syntax, compare VB with C#, and cover default values, returning nothing, and nested generics, with practical samples and alias usage.
Explore building a non-generic linked list in .NET, using node objects with data and next pointers, head management, and insert-at-head and index-get operations, plus tests verifying count and retrieval.
Turn a non-generic linked list into a generic one by replacing concrete types with T, using node of T, and returning default(T) for empty lists, then verify with unit tests.
Implement a linked list as an IEnumerable of T by declaring and implementing the IEnumerable<T> interface, including yield return, head node traversal, and tests for empty and populated lists.
Learn to use generic delegates to implement a remove‑where method on a generic linked list, using a Func<T,bool> condition to remove items by predicate in integers and people.
Implement a class that realizes the generic IEnumerable<T> interface and wraps a collection. Explore enumerable extensions such as to list, to array, count, first, where, select, and zip.
Demonstrates converting generic collections to arrays using the two array extension method and copy to, and explains that arrays implement IList<T> but are read-only.
Learn to use the IEnumerable.Cast extension method to convert legacy non-generic collections, such as ArrayList, into a generic, strongly typed IEnumerable<Person> for safer usage.
Learn how to use generic dictionaries in .NET, create dictionaries with int keys and string values, add and retrieve items, and use keys, values, contains key, and try get value.
Explore generic delegate types in the .NET framework, including action, func, predicate, converter, and comparison, with lambda-driven examples using person objects, last names, and list sorting.
Discover the system's generic collections, including dictionary, hash set, keyed collection, linked list, queue, stack, sorted dictionary, sorted list, sorted set, observable, and read-only variants, with notes on performance characteristics.
Explore the framework’s concurrent generic collections for thread-safe producer–consumer patterns, including concurrent bag, dictionary, queue, and stack, plus guidelines for exposing as IEnumerable, arrays, or read-only collections.
Explore how constraints enhance generics by requiring a parameterless constructor via the new constraint, as shown with a generic class and tests that demonstrate default values and type creation.
Explore type constraints in generics, enforcing T to derive from Person or implement the name interface, with relationship constraints and tests using Person and Employee to list names.
Understand the .NET generics new constraint, which requires a parameterless constructor for T, enabling safe new T creation and highlighting abstract class restrictions and factory alternatives.
Explore how unconstrained generic types cannot use equals or not equals, yet they can be converted to and from classes or interfaces, as tests demonstrate.
Explore equality in generic types by constraining T to a reference type, compare with equals and the double equals operator, and learn operator limitations.
Explore VB.NET generic constraint syntax, including class and interface constraints and the new constraint, and note differences from C#, with practical VB examples in the VB solution files.
Learn how to replace repetitive xml serialization code with generics, using a generic serialize method, type inference, and extension methods to handle invoices, purchase orders, and other types in dotnet.
Learn how Prism region manager handles a tab region with diverse views using generics, including get views of type and activate view meeting condition to manage charts and data entry.
Learn how to convert a non-generic class hierarchy to generics within a chart base, with chart definitions driving create new instance and serialization across multi chart and stat board.
Refactor the chart base class into generics, defining t chart and t chart definition, with constraints and a shared constructor, to streamline copying, definitions, and serialization in a real-world scenario.
Explore how generics replace reflection in modal dialog initialization by using a strongly typed arguments class and a generic show method. This enforces the initialize contract and prevents runtime errors.
Explore generics in .NET by comparing built-in enums with class based enumerations, showing constraints, parsing strings to enums, and using reflection for a safe, extensible enumeration pattern.
Explore unbound versus constructed and open versus closed types in generics, using examples like list of T and dictionary of string, T, while noting the terminology is mostly unimportant.
Learn covariance and contravariance in the dot net framework, including arrays, interfaces, and delegates, with the out keyword enabling covariance for reference types only.
declare covariant interfaces with the out keyword to permit return-type variance in .NET generics, while restricting usage to returns and, in some contravariant delegates, parameters; constraints remain unsupported.
Explore contravariance in generics by examining how parameter types become less derived, with contravariant delegates, actions, and interfaces, and contrast with covariance using the converter example.
Explore reflection in generics by inspecting generic types, open and closed forms, and constructing types with make generic type and activator to invoke generic methods.
Explore essential resources on generics in .NET, including MSDN documentation, a C# generics introduction, and guidance on generic collections, covariance, contravariance, and reflection to reduce code duplication and improve safety.
In this Generics in .NET training course, expert author Joe Wirtley will teach you how to use generics in .NET to eliminate code duplication and enforce static typing. This course is designed for users that already have a basic working knowledge of C#.
You will start by learning the generic basics, including generic methods, classes, and interfaces. From there, Joe will teach you about generics in the framework, generics and arrays, and delegate types. This video tutorial will also cover constraints and real world examples, such as XML serialization and modal dialog initialization. Finally, you will learn about some other topics including generics and enumerations, generic terminology, and covariance.
Once you have completed this computer based training course, you will have learned the necessary concepts required for using generics in .NET.