Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Newbie question on C#
Message
De
09/01/2012 15:14:27
 
 
À
09/01/2012 14:47:18
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01532477
Message ID:
01532559
Vues:
36
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 ?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform