DEV Community

Leandro Torres
Leandro Torres

Posted on

C# 13 novidades

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) { } 
Enter fullscreen mode Exit fullscreen mode

🎯 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++; } } } 
Enter fullscreen mode Exit fullscreen mode

🎯 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); 
Enter fullscreen mode Exit fullscreen mode

🎯 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); } 
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)