Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
Methods : to apply logic unit
Functions : to determine it
Properties : to choose it
In my knowledge, methods and functions are the same and they are the logical units of particular functionality. Properties are the attributes attached to the respective members like private, protect, public, type whether it is a integer, char, double, etc.. Thanks.
Methods and functions are psychologically the same things, that is a unit of business logic. In java the name 'method' is preferred over the name 'function'.
Properties on the other hand cannot be compared to methods or functions . The term 'Property' is used more generally for lots of different things and is more frequently used with GUI widgets when writing a desktop GUI software. For most of the developers, 'property' signifies an attribute or quality or characteristic of a particular Object in consideration e.g., ,Read-Only property of a TextField in Java determines whether the TextField is editable or not.
Method is a function which affect an objects.
Function is an just a way to repeat a group of commands by only calling the function name.
Properties is the values related to an object, these values change while the program be executed.
Note this example:
the cat is an object and it has a lot of Properties like food, health ... etc.
Also it has a lot of method like eating, sleeping, playing ... etc.
Which one is better to use when it come to return value for example
publicintEmployeeAge{ get{return intEmployeeAge};}And
publicintEmployeeAge(){return intEmployeeAge;}
Properties are a useful way of expressing a feature of an object, allowing get/set in a common way that can be used by APIs like data-binding, reflection and serialization. So for simple values of the object, properties are handy. Properties can't take arguments, should not have significant side-effects*, and should return quickly and repeatably. Also, there is no such thing as an "extension property" (to mirror an extension method) nor a generic property.
(*=lazy loading etc isn't uncommon, however)
Methods (C# doesn't have functions) are better for expressing things that either change the state, or which have an expectation of taking some time and not necessarily being reproducible. They don't tend to work in binding / serialization etc.
Note that properties are actually just a special way of writing methods. There is little functional difference. It is all about expressing intent. The one thing you don't want to expose, however, is fields (the actual intEmployeeAge instance variable).
So I would have:
publicintEmployeeAge{ get{return intEmployeeAge};}or just (if on the Employee object):
publicintAge{ get{return intEmployeeAge};}