Good staff ...

I'm doing a program in which I have a class (pharmacies) in which it has a list of medications (List <Medications>), but the medications class has 3 sub ...
When I insert an object in the list, everything works fine .... insert such an object from a subclass (Tablets c=new Tablets() / / Pharmacy. Add (c )... but when I access the data of the list, I can not get the attributes of the underclass ... I have a function in pharmacies that returns an object of the list, but the list abaut medications, only returns the attributes of the superclass ... ... anyone can help me. .. (I do not know if I explained well ...

Ok, heres a hint.

If you went into a shoe store, you'll find trainers, boots, shoes and sandals.

Now, they all go into shoe boxes

Same is true with your list, your list will hold your medications, however, you need to check the box as to which type of class you actually have in it.

So, once you've tested what class it is, you can then assign to an appropriate class, or, force the code to run as the class you found it to be so you can see then the additional attributes.

Class Farmacia
{
private List<Medicamentos> M = new List<Medicamentos>();
public Medicamentos k(string n)
{
.....
return M;
}
public add(Medicamentos a)
{
M.Add(a);
}
}
Class Medicamentos
{
string nome;
...
}
Class Comprimido:Medicamentos
{
int nComprimidos;
}
Class Xarope:Medicamentos
{
string embalagem;
}
I have something like this...I dont know if I have to use polymorphism or something else...
And If I use a List of objects (list<objects>)and not a list of Medicamentos(list<Medicamentos>??

You could use objects but your list of medicines should work..

And if I use objects, Can I do it:
List<object> M; new List<object>;
List<Medications> A=M;//??
How can I pass the objecto to a Medication??

I guess you havent looked on how you use lists.

List<object> M; new List<object>;
it was an error, but in the program I have that well done (List<object> M= new List<object>;)but t is not the problem...How can I transform a list of objects in a list of medications??

No, thats not what you did

You said an equivelent of

Tree of apples = 1 apple.

List<Medications> A=List<Object>M;
And if I do that??(Sorry if I'm boring)

No, thats not how it works, I guess your F1 button must be broken

Filipe11

Don't guess, look for an answer and then post a question. It helps when you show you're trying. I know it's frustrating but you're never going to go anywhere in programming if you just rattle off a bunch of guesses.

Read this
http://www.techotopia.com/index.php/C_Sharp_List_and_ArrayList_Collections

And what does your textbook say about using lists? ( I assume this is a course project or assignment of some sort)


*** And LizR is right - use the built in help function to help you figure things out as well

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.