Link to home
Start Free TrialLog in
Avatar of TheCommunicator
TheCommunicatorFlag for United States of America

asked on

What is difference between proerty and global variable?

Sometimes it makes me wonder that why do we have to use properties all the times when all they are used for is to hold some values while execution is going on?

Can't we use global variables for that? I mean I see that when we serialize and de-serialize the objects, we can take advantage of proprties being there but other than that what exact benefits that properties give as as opposed to the public variables?
ASKER CERTIFIED SOLUTION
Avatar of mac-will
mac-will
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also C# does not have "global variables" like C/C++

I assumed you meant public class fields.  Was that correct?
global is static and should be not a part of class object. proerty  can be a part of class object.

See following URL:

http://dotnetperls.com/global-variables-aspnet


Let me know for more information
Avatar of TheCommunicator

ASKER

Thank you so much guys. I am new to C# but the question here is why did C# people decide to introudce the whole new concept of Static properties rather than traditional C++ style properties?

I understand the point that mac-will raised that it does the validation but other than that GET and Set methods are nothing but  methods to retrieve value of that property whcih can be easily done with Public variables, right?

SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you so much guys. each author's comments was equally helpful and I am really thankful to you guys, :)