如何从arraylist检索对象值? [英] how to retrieve object value from an arraylist?

查看:112
本文介绍了如何从arraylist检索对象值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai all,


我正在尝试从网络服务获取arraylist并将其存储在新的arraylist中,但是它给了我以下错误

以下是我使用的代码

hai all,


i am trying to get arraylist form web service and trying to store it in new arraylist but it gives me the following error

following is the code i have used

display.MathService mymathservice = new display.MathService();
        object temp_result = mymathservice.display_messages(this.txtmessage.Text,"velu");
        final_result.Add(temp_result);
           for (int i = 0; i < final_result.Count; i++)
            {
                this.txtareamsg.Value += final_result[i].ToString();
            }



错误消息显示:
无法将类型为"System.Object []"的对象强制转换为类型为"System.Collections.ArrayList"."

现在告诉我我应该如何从数组列表中检索值,但是现在它只给我system.object..i,我不知道如何准确地找到索引值


请帮助我
在此先感谢



The error message says:
"Unable to cast object of type ''System.Object[]'' to type ''System.Collections.ArrayList''."

Now tell me how should i retrieve value from an arraylist but rite now it gives me only system.object..i dont know how to find out index value exactly


please help me
thanks in advance

推荐答案

hai谢谢,我已经解决了这个问题.感谢您的答复


hai all thank you i have solved this myself..thanks for the replies


this.final_result = new ArrayList();
        livechat.MathService mymath = new livechat.MathService();
        object[] temp = mymath.show_initial_msgs();
        foreach (object o in temp)
        {
            final_result.Add(o.ToString());
        }
        if (final_result.Count == 0)
        {
         //do nothing
        }
        else
        {
            for (int i = 0; i < final_result.Count; i++)
            {
                this.txtareamsg.Value = final_result[i].ToString() + Environment.NewLine;
            }
        }


您声明temp_result的类型为object.
final_result.Add()接受类型为System.Collections.Arraylist的参数.后者不能隐式转换为前者.

如果您知道display_messages()确实返回了ArrayList,则应首先声明temp_result.
如果它不返回ArrayList,那么它将根本无法工作.
You declare temp_result as of type object.
final_result.Add() accepts parameters of type System.Collections.Arraylist. The latter cannot implicitly be converted to the former.

If you know that display_messages() does return an ArrayList, then you should declare temp_result as such in the first place.
If it does not return an ArrayList, then it won''t work at all.


这篇关于如何从arraylist检索对象值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆