Edit, as per these comments:
Do you mean "Property" vs "Field"? public String S1; vs public String S2 { get; set; } – dana
Exactly dana, i mean the same. – Asad
Asad: you really need to try to use some other term to describe what you mean so that we can better understand your question. C# does not have global variables. The fields you can define in C# are not global - they are members of the class type. – dthorpe
Hi fellas,
Need your expert views over the difference between Field
and Property
. As in my project, I have used certain global variables which later on i changed to 'Properties' . My manager is asking what is the benefit of using Properties
of variables instead of Fields
.
Although I have replied him that Property
provides a kind of secure/safe/indirect access to Field
instead of modifying them directly if they are declared public
or protected
. But Please provide me with some more convincing arguments.
Thanks and Regards
@Asad:
You should get your terminology right: Fields
are not Global Variables
, C# does not have global variables (as a few commenters mentioned: you can simulate global variables, but you should not do that).