Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
What's the usecase for mutable records in C#9?

C# 9 adds records, finally! I've been waiting forever for this, it's supergreat! But I'm wondering what the point of having a record with { get; set; } is? It seems like records should be immutable and use { get; init; } for all their properties. Maybe I'm just too used to working with immutable data, but I don't get the point of mutable records. It just seems like it increases the likelihood of bugs in the code. Am I missing a really obvious and useful usecase?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

To start with: a record is just a quick, short notation to declare a class with a couple of useful features automatically added for free - but the end result is still a class like any other. It is syntactic sugar, with actually two flavours.

The extra-short positional syntax makes all properties init-only:

record Person(string FirstName, string LastName);

The less-short nominal syntax makes the developer responsible to specify set or init for each property:

record Person
{
    public string FirstName { get; set; }
    public string LastName { get; init; }
}

The reason behind offering both notations is that there is no 'one-size-fits-all'. Nominal syntax allows to create a class with very little code, with specific custom (im)mutability, and still get a copy constructor + cloning + hashing + comparison/equality for free.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda