Module 2: Advanced C# & .NET Core Features

Master advanced C# features and .NET Core specific programming patterns.

Back to Course|7 hours|Intermediate

Advanced C# & .NET Core Features

Master advanced C# features and .NET Core specific programming patterns.

Progress: 0/3 topics completed0%

Select Topics Overview

Modern C# Features (C# 8-12)

Explore the latest C# features that make .NET Core development more efficient and expressive

Content by: Vaibhav Nakrani

.Net Developer

Connect

C# 8.0 Features

Code Example
// Nullable reference types
string? nullableString = null;
string nonNullableString = "Hello";

// Pattern matching enhancements
public static string GetDisplayText(object obj) => obj switch
{
    string s when s.Length > 10 => s.Substring(0, 10) + "...",
    string s => s,
    int i => i.ToString(),
    DateTime dt => dt.ToString("yyyy-MM-dd"),
    _ => "Unknown"
};

// Using declarations
public void ProcessFile(string path)
{
    using var file = File.OpenRead(path);
    // File is automatically disposed at end of scope
}

// Static local functions
public void Calculate()
{
    static int Add(int a, int b) => a + b;
    var result = Add(5, 3);
}
Swipe to see more code

C# 9.0 Features

Code Example
// Records
public record Person(string FirstName, string LastName, int Age);

// Init-only properties
public class Product
{
    public string Name { get; init; }
    public decimal Price { get; init; }
}

// Pattern matching improvements
public static bool IsValidEmail(string email) => email is not null and not "" and contains "@";

// Target-typed new expressions
List<string> names = new() { "Alice", "Bob", "Charlie" };
Dictionary<string, int> ages = new() { ["Alice"] = 30, ["Bob"] = 25 };
Swipe to see more code

🎯 Practice Exercise

Test your understanding of this topic:

Ready for the Next Module?

Continue your learning journey and master the next set of concepts.

Continue to Module 3