Upgrade to Pro — share decks privately, control downloads, hide ads and more …

.NET 8 New Features with Code Examples

.NET 8 New Features with Code Examples

.NET 8 New Features with Code Examples

Devnot - Dotnet Konferansı 2024
25.05.2024
Sheraton Grand Ataşehir, İstanbul

Mert Metin

May 24, 2024
Tweet

More Decks by Mert Metin

Other Decks in Technology

Transcript

  1. .NET 8 New Features with Code Examples Mert Metin D

    E V N O T D O T N E T K O N F E R A N S I 2 0 2 4
  2. Mert Metin - Senior Software Engineer A B O U

    T M E mrtmtn _mertmetin mertmtn Blogcu Mühendis - Blogger QR to reach me
  3. 01 02 03 Performance Improvements Keyed DI Services C# 12

    - Primary Constructors - Collection Expressions - Spread Operator - Data Annotations - Default Values in Lambda Exp. - Exprerimental - Random.GetItems - Shuffle - Alias Any Type Enhanced Feature for .NET Dependency Injection Agenda - FrozenSet - CompositeFormat - SearchValues<T> - Benchmark Results* of the Improvements *All results have created by BenchmarkDotnet tool
  4. Primary Constructors - Simple class creation - Looks like method

    parameter Primary Constructor Typical constructor before C# 12
  5. Experimental Attribute An attribute which specifies as experimental feature on

    method or class Belongs to System.Diagnostics.CodeAnalysis
  6. Random.GetItems<T> Selects a specific number of items from a given

    set of elements randomly Drawback is; Resulting random collection can include duplicate entries. . Output Unexpected Output
  7. Shuffle Performs an in-place shuffle of an array. Useful in

    some cases; machine learning, gambling, online exam Belongs to Random class
  8. Keyed DI Services - Naming services with key. - Same

    service - different named services or different lifetimes Key, could be string or enum type Program.cs service declaration
  9. Keyed DI Services - Usages FromKeyedServices - Given key implemented

    on ActionMethod Program.cs service declaration
  10. FrozenSet<T> Benchmark Results - Slower creation because of modification the

    set - Faster lookup or reading because of immutable set
  11. CompositeFormat Allows to parse a composite format string once and

    reuse this instance multiple times. This approach significantly enhances performance, when the format string has created dynamically but used repeatedly.
  12. SearchValues Optimized in scenarios where the same set of values

    is frequently used for searching at runtime. Currently, only byte and char supported “String list” will be overloaded in .NET 9