Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Functionally</strong> there is no difference, they both return a value based on a parameter. In fact, properties are actually transformed into functions during compilation, since the notion of a <em>property</em> doesn't exist in <a href="http://en.wikipedia.org/wiki/Common_Intermediate_Language">MSIL</a>.</p> <p><strong>Semantically</strong>, however, there is a difference in how they <em>should</em> be used. Properties are meant as a way to expose the internal state of an object. Functions, on the other hand, are supposed to <em>operate</em> on an object's state to either provide an answer to a specific question (a <em>query</em>) or to modify the state in some way (a <em>command</em>).</p> <p>Here's an example:</p> <pre><code>Public Class Rectangle Private _size As Size ReadOnly Property Size() As Size Get Return _size End Get End Property Public Function IsSquare() As Boolean Return _size.Width = _size.Height End Function End Class </code></pre> <p>While <code>Size</code> simply exposes a <em>property</em> of the object, the <code>IsSquare</code> function actually <em>performs an operation</em> on the object's internal state in order to answer a question.</p> <p>Based on this principle, the most common use case for parameterized properties in VB.NET is in classes that <em>represent a sequence</em> of items, where the parameter is used to access a specific element in the sequence by its position or by some unique key. In other words, to create what's known as <a href="http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx">indexers</a> in C#.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload