Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Newbie question on C#
Message
De
09/01/2012 13:13:51
 
 
À
09/01/2012 11:46:38
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01532477
Message ID:
01532551
Vues:
41
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 ?


>A field is a variable that is visible to the entire class. If it needs to be seen from a different class, make it a property.
>
>
>>I don't think that having public field is the same as public memvar in VFP. But I could be mistaken.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform