Check out new C# 12 preview features! ⚡️
Three new features for C# 12😮 :
1️⃣ - Primary constructors for non-record classes and structs :
2️⃣ - Using aliases for any type:
3️⃣ - Default values for lambda expression parameters:
〰️〰️〰️〰️〰️〰️
#CSharp #DotNet
@ProgrammingTip
Three new features for C# 12
public class Student(int id, string name, IEnumerable<decimal> grades)
{
public Student(int id, string name) : this(id, name, Enumerable.Empty<decimal>()) { }
public int Id => id;
public string Name { get; set; } = name.Trim();
public decimal GPA => grades.Any() ? grades.Average() : 4.0m;
}
using Measurement = (string, int);
public void F(Measurement x)
{ }
var addWithDefault = (int addTo = 2) => addTo + 1;
addWithDefault(); // 3
addWithDefault(5); // 6
[ Article ] : https://devblogs.microsoft.com/dotnet/check-out-csharp-12-preview〰️〰️〰️〰️〰️〰️
#CSharp #DotNet
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
Telegram
Programming Tips Resources
.NET 8 - Keyed service dependency injection container support 🔝
Keyed services are useful when you have an interface/service with multiple implementations that you want to use in your app. What's more, you need to use each of those implementations in different places in your app.☄️
Sample:
〰️〰️〰️〰️〰️〰️
#DotNet #DotNetCore #AspNetCore #CSharp
@ProgrammingTip
Keyed services are useful when you have an interface/service with multiple implementations that you want to use in your app. What's more, you need to use each of those implementations in different places in your app.
Sample:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddKeyedSingleton<INotificationService, SmsNotificationService>("sms");
builder.Services.AddKeyedSingleton<INotificationService, EmailNotificationService>("email");
builder.Services.AddKeyedSingleton<INotificationService, PushNotificationService>("push");
[ Article ] : https://andrewlock.net/exploring-the-dotnet-8-preview-keyed-services-dependency-injection-support〰️〰️〰️〰️〰️〰️
#DotNet #DotNetCore #AspNetCore #CSharp
@ProgrammingTip
Please open Telegram to view this post
VIEW IN TELEGRAM
Telegram
Programming Tips Resources