
Explore how interfaces define contracts, require implementing classes to provide all members, and only support methods, properties, indexers, and events prior to C# 8.0.
Explore interface features in C# 8.0, including methods, properties, indexers, events, constants, operators, constructors, nested types, fields, explicit interface implementation, and default interface members, supported on .NET Core 3.0+.
Demonstrate default interface members in c# 8.0 with console demo, showing how a class can override and hide a default interface method and what happens when an implementation is missing.
Explore interface inheritance and explicit implementation in C# 8.0, demonstrating how to resolve member name conflicts with iBook and iBook better through explicit interface methods.
Demonstrate static methods and fields in interfaces in C# 8.0 with an iBook example, accessed via the interface name. The demo shows static fields are allowed; nonstatic members are not.
Learn how the static constructor in interfaces in C# 8.0 initializes static fields, enabling interface-level state not possible in earlier versions.
This demo shows using access modifiers on interface members in C# 8.0, including public, private, and internal, with default public and private methods for abstraction inside the interface.
Demonstrate using constants in an interface by declaring string constants, showing no errors when referenced, and highlighting new interface features in this C# 8.0 update.
Explore how the null reference type in C# 8.0 catches nullability issues at compile time and prevents null reference exceptions in applications handling null values.
Shows the problem of not using nullable reference types in a C# 8.0 project, causing a runtime null reference exception when accessing a null book title.
Demonstrates two ways to enable or disable null reference types in C# 8: editing the project file or using the enable approach, and shows how to address possible null values.
Learn to prevent null reference exceptions by using the question mark for nullable properties. Explore constructors and compiler warnings in the book model to handle nulls in title and authors.
Explore nullable reference types in C# 8.0 by returning null in a method, using the question mark to mark nullable references, and resolving compile-time warnings in consumer code.
Demonstrate enabling and disabling null reference type warnings in a specific file using directives, showing how to scope the warning and reenable it to prevent null reference exceptions.
Explore switch pattern matching in C# 8.0 and the new switch expression, replacing traditional switch cases with arrow syntax and the underscore default.
Explore switch pattern matching in C# 8.0 using an enum, updating a country enum to return values with arrow syntax, and replacing the default with underscore for streamlined case handling.
Explore how property pattern matching in C# 8.0 reduces if statements by matching date time properties like the year, as shown with 2022, 2021, and 2020.
Learn how to compare multiple properties in C# 8.0 property pattern by separating properties with a comma. See how to validate year and month together to evaluate true or false.
Demonstrate nested property pattern matching in C# 8.0 by modeling an employee and its address, then validate the employee ID is five and the address is current using property patterns.
Explore a demo of less than and greater than operators in property pattern matching for C# 8.0, showing how id values above or below five drive true conditions.
combine switch statements with property pattern matching to calculate employee bonuses by id, illustrating senior, mid-level, and junior tiers and how to apply nested properties in C# 8.
Explore tuple pattern matching in C# 8.0 with the double pattern to assign multiple values, use a table for country and state combinations, and simplify complex conditionals.
Explore the null coalescing assignment operator in C#, using a left-hand field that is initially null to receive a right-hand value, then show that once non-null, it won’t be reassigned.
Demonstrate initializing a possibly null list of integers with the null-coalescing operator, safely adding elements, and displaying the results using a for each loop.
Explore static local functions in C# 8.0 and see how the static keyword prevents capturing outer variables in inner methods, making code safer and more predictable.
Demonstrate using a static local function inside a parent method to build a full name from two parameters, first name and last name, returning a string.
Discover the index from end operator ^ in C# 8.0, which lets you access the last elements of a sequence using the umbrella symbol rather than length minus one.
Demonstrate accessing array elements with the index-from-end (^) operator in C# 8.0, including first and last items, length minus one, and handling out-of-bounds errors.
Explore the range operator in C# 8.0, using the two dots syntax (start..end) to extract a sub array; start is inclusive, end is exclusive, enabling flexible data slicing.
Explore four practical ways to use the range operator in C# 8.0, including start and end boundaries, only end, only start, and index-from-end selections, with end-not-included behavior.
Declare ranges and indices as variables, pass them into a sequence to retrieve data, and avoid hardcoding values while using either the index or the range.
C# 8.0 was introduced with DotNet Core 3.0 with so many great improvements and features. There are so many changes in Interfaces, Pattern Matching, Handling Null Reference exceptions, and added some new Operators.
All these C# 8 features are must learn and use in your projects. C# 8 Features will help you to write complex logic with minimum code.
C# Latest Features (C# 8.0)
Interface:
Interfaces in C# 8.0 allows us to write member body, static fields, static constructor, constants, access modifiers (public, private, internal, etc) and so many other features.
Nullable Reference Type:
Nullable reference type allows us to avoid Null Reference Exception at the compile time. C# developers can enable/disable the nullable features on project/file levels. If the Nullable reference type is enabled then the compiler will give a warning whenever there are possibilities of a null error.
Switch Pattern Matching:
Switch pattern matching allows the C# developers to write the switch statement without using the case, or default keywords. This will allow us to focus only on logic rather than unnecessary keywords.
Property Pattern Matching
Tuple Pattern Matching:
Tuple pattern matching in C# allows us to write complex logic with very less code. This is easy to write, read and clean code.
Null-Coalescing Operator:
Null-Coalescing Operator is a new operator added in C# 8. This Null-Coalescing Operator allows the C# developers to assign the right side expression only if the left-hand side value is null. (Very Useful)
Indices and Range:
There is a new way to get the sequence value from the end instead of array.length-1. And the Range is a new operator. The Range operator is used to get the subsequence from a sequence with start and end boundaries.
Static Local Functions