Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generic list question
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 5.0
OS:
Windows 7
Network:
SAMBA Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01611163
Message ID:
01611274
Vues:
22
>The reason I moved to derived classes was for maintenance , if I add another member to my interface I obviously have to implement it in all my classes ( which is what I've reverted to anyway because of the empty objects ) , I don't totally understand why the derived class method resulted in null values, the structure I had in mind ( which didn't work ) was, to define an interface,implement the interface in a base class, create subclasses of the base class, the reason I need subclasses is I decorate the properties I require for my CSV serialiser with a custom attribute which allows me to sort the order they are serialised and include or exclude them from the output. What I find inconsistent with interfaces ( and I love them ) is if you subclass a base class that implements an interface you don't have to implement the interface in your subclass - which is why I went that route but ended up with empty objects, in one of my methods for adding an object to a list for testing purposes instead of using new T() I typed my class instance ( I was using a derived class at this time )
>
>
>Tariff1 t = new Tariff1();
>t.SomeProperty = "Viv";
>t.OtherProperty = "Greg;
>this.Data.Add(t);
>
>
>Now this is what is confusing me, if you inspect "t" it has "Viv" and "Greg" as values, Data[0] doesn't

I think that sounds as if you have defined the same properties (newed) of the base class in the derived class. If this.Data is typed to the base class then you will see the base class properties which will be null. To get the valuie of SomeProperty you would need to cast to the derived type :
((DerivedClass)list[0]).SomeProperty

If the above is not the case can you post the relevant bits of the base and derived class....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform