DEV Community

Leandro Torres
Leandro Torres

Posted on

1

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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay