What's New in C# 12 - Learn Every Single Feature Added in C# 12 With Example

Sdílet
Vložit
  • čas přidán 22. 05. 2024
  • What's New in C# 12 - Learn Every Single Feature of C# 12 With Example.
    In this video we will learn:
    Primary Constructor in C# 12:
    The primary constructor is a new way of writing the constructors in the C# programming language. We will start learning from
    1. What is a Primary Constructor in C# and how to use them in C# applications.
    2. How to assign primary constructor parameters to a field or property.
    3. How to use multiple constructors with Primary Constructors
    4. Difference between Primary Constructors and Records in C# (This is interesting)
    5. Passing parameters to parent class constructor while using Primary Constructors
    6. Real-Time Use Case of Primary Constructors in C# 12. We will use the primary constructor in asp.net core Web API project to handle the EF Core DbContext Dependency Injections.
    Collection Expressions in C# 12: Collection expressions provide the simplest way to define the collections in C#. You will also learn about how to use the spread operator using collection expressions.
    Ref Readonly Parameters:
    C# introduced "in parameters" to easily pass references that can't be modified. These in parameters work with both variables and values, and you don't need to add any special annotations to use them.
    The new "ref readonly parameters" in C# make it clearer when APIs use either ref parameters or in parameters.
    Default Lambda Parameters: You can now define default values for parameters on lambda expressions. The syntax and rules are the same as adding default values for arguments to any method or local function.
    Alias Any Type: You can use the using alias directive to alias any type, not just named types. That means you can create semantic aliases for tuple types, array types, pointer types, or other unsafe types.
    Inline Arrays: Inline arrays are used by the runtime team and other library authors to improve performance in your apps. Inline arrays enable a developer to create an array of fixed size in a struct type. A struct with an inline buffer should provide performance characteristics similar to an unsafe fixed-size buffer.
    Experimental Attribute: You can label types, methods, or assemblies with the System.Diagnostics.CodeAnalysis.ExperimentalAttribute to signify an experimental feature. If you try to use a method or type marked with this ExperimentalAttribute, the compiler will give you a warning. All types within an assembly labeled with the Experimental attribute are considered experimental.
    Interceptors in C# 12 are added as preview features. An interceptor is a method that can replace a call to a specific method during compilation. This replacement is done declaratively by the interceptor, which specifies the source locations of the calls it intercepts. Interceptors offer a way to alter the behavior of existing code by introducing new code into a compilation, such as in a source generator.
    When using an interceptor in a source generator, the goal is to modify existing code rather than add new code. The source generator achieves this by substituting calls to an interceptable method with calls to the interceptor method.
    Timestamp:
    Introduction to What's New In C# 12 00:00
    How to Install C# 12 (System Setup) 01:00
    Primary Constructor in C# 12 03:44
    C# 12 Collection Expressions in C# 12 19:50
    C# 12 Ref Readonly Parameters 24:56
    C# 12 Default Lambda Parameters 27:55
    C# 12 Alias Any Type 29:16
    C# 12 Inline Arrays 33:42
    C# 12 Experimental Attribute 35:07
    Interceptors in C# 12 37:35
    Code Repository: github.com/nitish-kaushik/wha...
  • Věda a technologie

Komentáře • 10

  • @pazuzufraney1
    @pazuzufraney1 Před měsícem +1

    Wow the use of [] and .. is directlybborrowed from typescript. .. means add a shallow copy to list or areay.. [] means treat as anonymous array.. this is good for c#

  • @vijayvadnal9715
    @vijayvadnal9715 Před 24 dny

    Nice explanation on Primary constructor, what is impact on DI if we use Primary Constructor?

  • @keshavjangra8075
    @keshavjangra8075 Před 5 měsíci

    Hello Sir , This Video is very helpful with All topics you have covered , But I love these 2 features 1: Collection Expressions and 2: Alias Any Type . Really Helpfull

    • @WebGentle
      @WebGentle  Před 5 měsíci

      Good choice. These two are really helpful concepts.

  • @barath8291
    @barath8291 Před 2 měsíci

    How primary constructor work when come to dependency injection ?

  • @rokckerzzzz6080
    @rokckerzzzz6080 Před 5 měsíci

    Thanks for the new features of C#12. For InterceptsLoaction can we use virtual path?

    • @WebGentle
      @WebGentle  Před 5 měsíci

      Thank for the feedback. As of now full path is required for interceptors

  • @anuragmohanty9329
    @anuragmohanty9329 Před 4 měsíci

    Could you please give an real time example for All his new features.

  • @sangola6380
    @sangola6380 Před 5 měsíci

    Hello sir,average student can go to developer role or stay to supporting role?

    • @WebGentle
      @WebGentle  Před 5 měsíci +1

      No one is average. One has to work hard in the right direction with right tools.
      Not only developer if you work hard in the right direction you can launch new products and libraries.
      Follow your passion ❤️