What is the difference between a {get; set;} property and a public variable?

Asked

Viewed 31 times

0

I’m programming in C# and I always see them use propriedades allowing to take and set the value of the variable, but what is the sense of this? When you let it just take the value or something I kind of understand, because it’s less work than creating a método to take this value, but when it is the simplest I do not understand. There is real difference between the two codes below?

public int Numero { get; set; }
public int numero;
  • 1

    You are free to abstract how you will rescue or how you will save the value. Not to mention that there may be frameworks that go after methods getters and setters (the existence of these frameworks is too common in Java, I don’t know as much as C#)

  • Really, I was using SQLite.netfor Xamarin and to use some features like autoincrement, if I’m not mistaken, you need to getter and setter.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.