CutiePie

Hi all,

I have made a program using Generic classes and all..but now i need to change it to Arraylist...I started working with Generics and found it easier to understand, so thats why now i dont know how to change it..Here is the sample code that i have to change:

private List<Alternative> alternatives = null;

[XmlArrayItem("alternative")]

public List<Alternative> Alternatives

{

get

{

if (alternatives == null)

{

alternatives = new List<Alternative>();

}

return alternatives;

}

set

{

alternatives = value;

}

}

----------------------------------------------------------------------------------------------------------

Now can someone please guide me..how and where to put Arraylist Alternative is again another class...

Any help will be greatly appreciated.

Thanks a lot,

Regards.



Re: Visual C# Language how to change generics to arraylist?

Manju Sandhu

Hi,

Just replace your code like this

private ArrayList alternatives = null;

public ArrayList Alternatives

{

get

{

if (alternatives == null)

{

alternatives = new ArrayList();

}

return alternatives;

}

set

{

alternatives = value;

}

}

Now whereever you have to use it. You have to typecast object of Arraylist to Alternative type. Since ArrayList store 'Object' type elements.

I hope this solve your problem.

Regards,

Manju Sandhu





Re: Visual C# Language how to change generics to arraylist?

CutiePie

Thank you very much for your reply...Can you tell me is it possible to do something with arraylist like i did for generics...as follow:

MicroComponentIdentity mci = mcomponentDescription.MicroComponentList.Find(delegate(MicroComponentIdentity aux) { return aux.MicroComponentId == mcId; });

-----------------------------------

I mean the way we can use Find in generics and ForEach in generics...is there anything we can do with arraylist or some other way that i can follow..to get the result faster...so as to get a better performance...

again, MicroComponentIdentity is a class...

Thank you once again,

Regards.





Re: Visual C# Language how to change generics to arraylist?

Manju Sandhu

Hi,

alternatives.IndexOf(objectToSearch);

alternatives.Contains(objectToSearch);

You can do this like this.

Hope this answer your question.

Regards,

Manju Sandhu





Re: Visual C# Language how to change generics to arraylist?

CutiePie

Thanks once again...I understood your description..but whenever i am trying to do as follow:

MicroComponentIdentity microComponent = (MicroComponentIdentity)micro;

It gives me error saying it can not convert XML NODE to MicroComponentIdentity....

i think the reason being...when i am making this "micro" as arraylist then it is storing everything in the form of array and now when i am trying to convert it to my class then its not doing it Sad

can you suggest me something else

thank you.





Re: Visual C# Language how to change generics to arraylist?

Manju Sandhu

Hi,

micro is your ArrayList Name. If is it so then you have to do this like this.

MicroComponentIdentity microComponent = (MicroComponentIdentity)micro[0];

0 specify index.

Regards,

Manju Sandhu





Re: Visual C# Language how to change generics to arraylist?

CutiePie

No no...micro is not the list name..its one of the elements of the list...coz i m using it as follow:

foreach (object micro in mcomponentDescription.MicroComponentList)

{

MicroComponentIdentity microComponent = (MicroComponentIdentity)micro;

}

so now wat to do Sad

Regards





Re: Visual C# Language how to change generics to arraylist?

Manju Sandhu

Hi,

Can you provide me that code in which you are populating 'mcomponentDescription.MicroComponentList'.

Regards,

Manju sandhu





Re: Visual C# Language how to change generics to arraylist?

CutiePie

hi,

here is the class :

[XmlRoot("MicroComponents")]

public class MicroComponents

{

private ArrayList mclist = null;

public MicroComponents() { }

[XmlElement("mc")]

public ArrayList MicroComponentList

{

get

{

if (mclist== null)

{

mclist = new ArrayList();

}

return mclist;

}

set

{

mclist = value;

}

}

}

----------------------------------------------------------------

Now inside the microcomponentIdentity....i am storing all this :

private string id;

private string type;

private string mcname;

private MicroCompParameters parameters = new MicroCompParameters();

private List<Alternative> alternatives = null; (this will be changed to arraylist as well later on)

-------------------------------------------------------------------

and when i run it then i saw that the way my MICROCOMPONENTLIST is being populated is:

1. Dimension 5

2. Dimension 5

--------------------------------------------------------------------

So, that means each of these 5 variables from microcomponent identity are stored inside my list...Thats why i am having problems in retrieving the data Sad

Please guide me.

Regards.