1: This is a simple property and can be used in much the same way as in a public field. If you have a reason to show get and set operations to other users (i.e. other classes), and you don't need anything interesting, thatβs all. This can also be written using "auto-properties",
public static bool isInitialEditMapPageLoad {get;set;}
automatic details are written much faster and, in my opinion, much more readable than a full declaration (if I see a full declaration using the support field, I expect to find some complexity).
2: This shows one of the reasons for the properties: using some logic to return the value, rather than return the value directly. Someone can set this value as they will be a public field whenever they want. They can get the value whenever they want, with the proviso that false means that this is not a boot, or the user is not authorized, that is, some (simple) logic is executed before the value is returned.
3: This behaves like a public field for READ ONLY - someone can get the value but not set it. This is essentially a value that is read only by external code (not to be confused with the readonly keyword)
4: Result for compilation for me. Assuming this should be a method declaration, manually defining a getter, as in Java, it looks like Example 3. I believe that there are other problems that make this not quite so, for example, if you want to turn this into a dependency property and etc. Unfortunately, my knowledge in this area is declining.
===========
Typically, user properties restrict access to your class data. As a principle, everything that you can hold by allowing another code to touch should be saved this way. In practical terms, you will want to set the values ββin the classes to change the display method, change the data presented, etc. Use properties to maintain maximum control over this interaction.
If other classes need to look at something in their class, you will need to open the getter, but not the setter. This is not possible with fields unless you use the Java method to create a custom getter method. They also allow you to perform calculations or checks before returning or adjusting data. For example, if you have an integer value that must be within a certain range (a range that may vary depending on the state of your object, even), you can check in your setter to make sure that this condition is met before your actual update value.
Try to avoid the trap by simply installing everything as an auto program - this is no different from making everything publicly available. Keep everything as private as possible. Without getters, if it is not necessary, there are no setters if it is necessary, and setters must carry out any small logic necessary to verify the input before accepting it if necessary. However, avoid another trap: put a lot of code in getters / setters. If you need more than a few lines, you should create a method rather than a property, simply because it gives a bigger hint to others, using your code, that something big will happen.