I have a structure in C#.net. I have created an object of that structure. I need to cast this object of structure into ArrayList. I am using :
OrderMessageStructure.OrderMessage orderToModify = new OrderMessageStructure.OrderMessage(); object neworderobject = (object)orderToModify; ArrayList arr = new ArrayList(); arr = (ArrayList)neworderobject;
But I am getting error ‘Unable to cast object of type ‘OrderMessage’ to type ‘System.Collections.ArrayList’.’
How to convert object/structure into ArrayList?
Your question doesn’t have quite enough information to give a sure answer.
If you want to make an ArrayList of OrderMessage objects then you need to create the arraylist FIRST and then ADD instances of OrderMessage.
If you want a strongly typed ArrayList of OrderMessage then use List from the Generic Namespace and ADD instances of OrderMessage to it.
If your OrderMessage has an array structure in it then you will need to add a method to it that returns an arraylist. You will have to write the code converting the OrderMessage to an ArrayList.