
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.
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.
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.
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.
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.
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.
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