properties vs methods

  • Thread starter Thread starter rahul gupta
  • Start date Start date
R

rahul gupta

i m in a confusion.
though there is syntactical differences between properties and
methods.
but same type of logics can be implemented by both i.e we can do same
piece of work from both.
Both can be used to manage private fields.
Then why we prefer properties over functions????
Why properties are more advantageous then methods
 
i m in a confusion.
though there is syntactical differences between properties and
methods.
but same type of logics can be implemented by both i.e we can do same
piece of work from both.
Both can be used to manage private fields.
Correct.

Then why we prefer properties over functions????
Why properties are more advantageous then methods

You use properties and the syntax:

o.P = o.P + 1;

instead of:

p.SetP(o.GetP() + 1);

because that is the coding convention in C# for simple
data access.

If you don't follow coding convention then you will confuse
the readers of the code.

Was it a good idea to add properties to the C# language
8 years ago?

I am not convinced that it was. Properties does not provide any
restrictions on what they can do, so it is just a second syntax
for the same. C++ and Java have lived fine without them.

But MS thought differently back in 2002 (or whenever the
decision was made). If I were to guess on why, then I would
say that properties is a common concept in the VB/COM world
and there may be compatibility reasons to add it to .NET!

But no matter what one believe in that regard, then the
decision was made and that is how it is.

You must code C# like it is - not like you
think it should have been.

Arne
 
You usepropertiesand the syntax:

o.P = o.P + 1;

instead of:

p.SetP(o.GetP() + 1);

because that is the coding convention in C# for simple
data access.

If you don't follow coding convention then you will confuse
the readers of the code.

Was it a good idea to addpropertiesto the C# language
8 years ago?

I am not convinced that it was.Propertiesdoes not provide any
restrictions on what they can do, so it is just a second syntax
for the same. C++ and Java have lived fine without them.

But MS thought differently back in 2002 (or whenever the
decision was made). If I were to guess on why, then I would
say thatpropertiesis a common concept in the VB/COM world
and there may be compatibility reasons to add it to .NET!

But no matter what one believe in that regard, then the
decision was made and that is how it is.

You must code C# like it is - not like you
think it should have been.

Arne

thanx i got the answer :)
 
Back
Top