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

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay