c# - why would an interface have properties in them -


why interface have property in it? understand interface contract why ever need property within interface? many thanks

well let's suppose interface represents collection of objects.

further suppose want know how many objects.

tada! use property int count {get;}

technically, never need property because can write setx() , getx() method. it's kind of true never need one.

however, frameworks use reflection find properties, frameworks serialization , deserialization. in cases, properties are needed.

in practical terms, properties more readable methods, , used should convey additional information such "it not going expensive read value" , "reading value not cause observable side-effects". (both should apply implemented property getters.)


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -