The first code is a syntactic sugar for the second, roughly. So there's no difference between them, this you know. If it is the same, why doubt? The first one has everything it has in the second, you just can not see it written there.
If you write the first one is the same as the one you wrote the second one, it is obvious that it has no difference. You may be wanting to see something else that does not exist there.
There is a private field in the first too, after all where will it save the die? Must be in a class variable (static or instance, in case it is instance). Just because you did not type or do not see does not mean it is not there.
The code for get
and set
are methods that execute a code, however simple they are, but do not store values, only the field can store a value. Both are public.
Alias, a lot of people think that one line of code can be faster than several lines. This is obviously not true, what is behind that line is what defines what it does. What you see is always an abstraction of something greater. In fact, not even an Assembly line defines how much a processing costs, each instruction its different cost.
See what the generated code looks like:
[DebuggerBrowsable(DebuggerBrowsableState.Never), CompilerGenerated]
private int <numero>k__BackingField; //o campo privado criado pelo copilador
private int _numero; //o cam criado manualamente
public int numero
{
[CompilerGenerated]
get
{
return this.<numero>k__BackingField; //o acesso criado pelo compilador
}
[CompilerGenerated]
set
{
this.<numero>k__BackingField = value; //a mutação criada pelo compilador
}
}
public int Numero
{
get
{
return this._numero;
}
set
{
this._numero = value;
}
}
See the
21.07.2017 / 00:00