C# 13 novidades
Leandro Torres
Posted on November 9, 2024
O Oleg Kyrylchuk fez um post no site dele sobre algumas novidades do C# 13. Vou reproduzir por aqui algumas para registrar.
🎯 Params Collections
/ Before C# 13
void Method1(params object[] args) { }
// C# 13
void Method2(params IList<object> args)
{ }
// C# 13
void Method3(params ICollection<object> args)
{ }
// C# 13
void Method4(params ReadOnlySpan<object> args)
{ }
🎯 New Lock Object
public class OldLock
{
private readonly object _lockObj = new();
private static int sharedResource = 0;
public void IncrementResource()
{
lock (_lockObj)
{
sharedResource++;
}
}
}
public class NewLock
{
private readonly Lock _lockObj = new();
private static int sharedResource = 0;
public void IncrementResource()
{
using (_lockObj.EnterScope())
{
sharedResource++;
}
}
}
🎯 New Escape Sequence
//OLD
string text = "\u001b[32mThis is green text\u001b[0m";
Console.WriteLine(text);
//NEW
string text = "\e[32mThis is green text\e[0m";
Console.WriteLine(text);
🎯 Partial Properties And Indexers
public partial class Foo
{
[GeneratedRegex("abc|def")]
private static partial Regex AbcRegex { get; }
public bool IsMatchAbc(string text)
=> AbcRegex.IsMatch(text);
}
Links e Referências:
👉 Oleg Kyrylchuk
👉 What’s New in C# 13
Até a próxima! 👊
☕😊 Agora você pode apoiar comprando um café para mim
💖 💪 🙅 🚩
Leandro Torres
Posted on November 9, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.