Re: Is this good use of Properties?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Brett,

The disadvantage of both methods is that you encapsulate=do nothing.
Start thinking in objects means a lot of times do completely away with
accessors! It will really help you to be really critical about every
one of those.


Rick



On Mon, 9 May 2005 09:17:09 -0400, "Brett" <no@xxxxxxxx> wrote:

>If I do this without declaring a corresponding field, is it considered bad
>design? What are the advantages or disadvantages to either method? Notice
>there is not set.
>
>public string URL
> {
> get
> {
> return "www.somewhere.com/test.aspx";
> }
> }
>
>vs. a more common approach:
>
>
>private readonly string _URL = "www.somewhere.com/test.aspx";
>
>public string URL
> {
> get
> {
> return _URL;
> }
> }
>
>Also, if I only have a get accessor, is it necessary to declare the field as
>readonly?
>
>Thanks,
>Brett
>

.