Kondapanaidu said:
What is the difference between Properties and functions.
Define "functions". IMHO, both properties and methods (the labels that .NET
uses) are functions.
Why dont we go for functions instead of properties.
If you mean "why don't we go for methods instead of properties", IMHO it's
all about using the language to more clearly describe what something does.
To me, a property is a way to get or set some state of a class (oddly
enough, this fits very well with how one defines a property

). A method
is a part of a class that actually *does* something. Obviously, you could
use a method to get or set state. You could even use a property to actually
*do* something. But in the latter case, you would always have to return
something or accept a value. One of the things I'm finding is that, because
of the strong emphasis on exception handling in .NET, very few of my methods
ever actually return something and those that do are almost always returning
an object (often newly created).
So in a large majority of cases, another major differentiating factor is
that properties always have data going into or out of the class, while a
method does not return any specific value.
Yet another way to look at it is that properties are often a bi-directional
way to communicate to a class. That is, data can go either direction in a
symmetric way. That's not strictly required, of course, and I do have
plenty of read-only properties (I even made a write-only property once...I'm
still trying to figure out if I like that or not

). Methods may be
bidirectional in some sense, but you have to go to some trouble to make them
symmetrically so, and even if you do they won't have the clean,
easy-to-understand semantics of a property.
IMHO, whether to use a property or a method depends a LOT less on how much
work there is to do than the semantics of the actual function. I can well
imagine some state that requires a significant amount of work to change but
which would still more properly be implemented as a property, at the same
time that I can imagine a method that is relatively simple (maybe only a few
lines of code, even) and yet which would make no sense as a property at all.
Pete