Difference when initializing values of a class?

0

I have a class with too many variables, I need to initialize the values empty depending on the type of data, I see that I can do it in two ways:

public class Documento
{
    public Document()
    {
        Tipo = "";
        Numero = "";
    }

    public string Tipo { get; set; }
    public string Numero { get; set; }
}

and in this other way:

public class Documento
{
    public string Tipo { get; set; } = "";
    public string Numero { get; set; } = "";
}

What is the difference?

    
asked by Jose Sebastian Rico Leyton 19.09.2018 в 21:44
source

1 answer

2

The objective you achieve is the same, only that it applies features of different versions of c #

Using the constructor to define the initialization is compatible from the first versions of C #, instead using the initialization of properties you will need c # 6 or higher

Automatic Property Initializers

But in summary are two ways to achieve the same thing

    
answered by 19.09.2018 / 21:58
source