Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie question on C#
Message
From
09/01/2012 15:14:27
 
 
To
09/01/2012 14:47:18
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01532477
Message ID:
01532559
Views:
38
Fair enough. We agree on 'best practice' but I think it's important to be clear that this is not a constraint imposed by the language - there's a place for private and virtual properties as well ......

Something else many do not realize : there's a real difference between public properties and public fields. If you change a member from field to property even though the way in which you access the member externally remains the same you have a breaking change - any class referencing that member will also need to be recompiled.....


>Yes, they can be, but the *shouldn't* be.
>
>
>>Sorry, don't think that is valid. Fields *can* be public eg:
public class Class1
>>    {
>>        public string NameField;
>>        public string NameProperty { get; set; }
>>    }
Two members; one a field, one a property. Both are visible outside the class. That said, I agree that members intended to be visible outside the class should definitely be declared as properties not fields (and for very good reasons). Whether the scope should be public, protected or internal is a secondary consideration....
>>In the same vein class level fields should almost always be private - but again, in some circumstances 'protected' may make more sense ?
Previous
Reply
Map
View

Click here to load this message in the networking platform