Tuesday, 4 June 2024

C#10

 

Assignment and declaration in the same deconstruction

In the previous versions of C#, developers can either assign values to existing variables or declare new variables in deconstruction. The combination of assigning a value to an existing variable and declaring a new variable was restricted. This restriction is now removed, and you can assign a value and declare a new variable in a single deconstruction.

Before C# 10

(string name, string email) = var employee;

Or
string name;
string email;
(name, email) = employee;

In C# 10

string name;
(name, string email) = employee;

Assignment And Declaration in C# 10

Conclusion

Thank you for reading this blog post. I hope you now have a good idea about the top five features in C# 10. Use these features when coding with C# 10 to make your code more readable and productive.

Old format

namespace ConsoleAppcore
{
    internal class User
    {
    }
}

New format for C# 10

namespace ConsoleAppcore;
internal class User
{
}

No comments:

Post a Comment

7 Common mistakes in Dot Net — You can avoid

  There are many common mistakes made during .NET (ASP.NET, .NET Core) development, which affect performance, security, and code… Code Crack...