Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You said <code>A = A</code> and <code>B = B</code> is the same, but this is not true! You can make changes in a propery's getter and setter so <code>A = A</code> can change the variable like in the example below:</p> <pre><code>public Int32 A { get { return _A++; } set { _A = value; } } </code></pre> <p>So the compiler doesn't know if it is a misstake or not. Of course i would avoid such situations because its not so easy to work with code like this ( a.e. if you just have a assembly and don't know why A is changing each time ) and i would avoid to expose a explicit setter of such a property and prefer something like below.</p> <pre><code>public UInt32 UniqueID { get { _UniqueID++; } } public void Reset() { _UniqueID = 0; } </code></pre> <h3>Conclusion</h3> <p>A compile time error isn't making any sense here because the compiler don't know what happens in the property ( Remember: <strong>A property is just a simplification of two methods, set_MyProperty and get_MyProperty</strong> ), also if the property changes ( a.e. by beeing virtual ) the behaviour may change too.</p> <h2>(EDIT) Avoid missleading namings</h2> <p>I write property and parameters in the same way you are doing it. So as example how a simple class might look:</p> <pre><code>public class MyClass { public Int32 Sample { get; private set; } public MyClass(Int32 sample) { Sample = sample; } } </code></pre> <p>I'm getting into in the same trap like you every week around ~1 time so i did never thought about changing the namings. But there are some suggestions what you could use:</p> <ul> <li>Use <code>p</code>(arameter) as prefix, however this is something which i would not recommend because it makes the code unreadable IMHO.</li> <li>Use <code>value</code> as postfix, this seems ok for me. So instead of <code>sample</code> you would have <code>sampleValue</code> which is different to <code>Sample</code> ( The properties name ) and it should be easier to detect if the properties name is used instead of the parameters one</li> <li>Use <code>_</code> as prefix. I would't use it because i already use <code>_</code> as prefix for members to enable fast access to them and makes intellisense look strange IMHO.</li> </ul> <p>I think this depends totaly on you personal or company coding style but i personally would use <code>Value</code> as postfix.</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