Re: Is this good use of Properties?
- From: "Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 9 May 2005 15:31:31 +0200
The C# compiler, unlike the brain-dead VB compiler, can figure out for
itself that if a property only has a get accessor then it's probably a
read-only property. It's one of my VB pet hates.
Perhaps the type of property you mention would be better as a static
property similar to Pi in the Math class or "Red" in the Color class.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Brett" <no@xxxxxxxx> wrote in message
news:%23Cry0lJVFHA.2172@xxxxxxxxxxxxxxxxxxxxxxx
> 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
>
.
- Follow-Ups:
- Re: Is this good use of Properties?
- From: Brett
- Re: Is this good use of Properties?
- References:
- Is this good use of Properties?
- From: Brett
- Is this good use of Properties?
- Prev by Date: Re: Is this good use of Properties?
- Next by Date: Re: HTTP 403 Forbidden
- Previous by thread: Re: Is this good use of Properties?
- Next by thread: Re: Is this good use of Properties?
- Index(es):
Relevant Pages
|