本文介绍了如何将对象/结构转换为arraylist?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#.net中有一个结构.我已经创建了该结构的对象.我需要将此结构对象转换为ArrayList.我正在使用:

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;

但是我收到错误消息无法将类型为'OrderMessage'的对象转换为类型为'System.Collections.ArrayList'."

But I am getting error "Unable to cast object of type 'OrderMessage' to type 'System.Collections.ArrayList'."

如何将对象/结构转换为ArrayList?

How to convert object/structure into ArrayList?

推荐答案

您的问题没有足够的信息来给出肯定的答案.

Your question doesn't have quite enough information to give a sure answer.

如果要创建OrderMessage对象的ArrayList,则需要先创建数组列表,然后创建OrderMessage的ADD实例.

If you want to make an ArrayList of OrderMessage objects then you need to create the arraylist FIRST and then ADD instances of OrderMessage.

如果要使用OrderMessage的强类型ArrayList,请使用通用命名空间中的List和OrderMessage的ADD实例.

If you want a strongly typed ArrayList of OrderMessage then use List from the Generic Namespace and ADD instances of OrderMessage to it.

如果OrderMessage中具有数组结构,则需要向其添加一个返回数组列表的方法.您将必须编写将OrderMessage转换为ArrayList的代码.

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.

这篇关于如何将对象/结构转换为arraylist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 02:34
查看更多