如何处理类型"Object {System.Collections.Generic.List< object>}" [英] How to handle type “Object {System.Collections.Generic.List<object>}”

查看:46
本文介绍了如何处理类型"Object {System.Collections.Generic.List< object>}"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次遇到这样的物体.

This is my first time encountering with such an object.

>调试期间我的本地窗口的图像链接<

因此,很简单地说,当唯一的"test"给出的方法与普通对象完全相同,并且我不知道要强制转换时,如何访问CardNO或ItemID的值,分别为296和130.它来.我什至不能做这个'test [0]'.

So to put it very simply, how do I access the value for CardNO or ItemID, which is 296 and 130 respectively when the only methods 'test' give are exactly like a normal object and I don't know what to cast it to. I can't even do this 'test[0]'.

这是测试"的来源:

private void ListBoxIssue_OnDragEnter(object sender, DragEventArgs e)
    {
        var test = DragDropPayloadManager.GetDataFromObject(e.Data, typeof(CommsItem));
    }

推荐答案

使用

var item = (CommsItem)((List<object>)test).FirstOrDefault();

在转换之前,请务必先检查 test 是否为 List< object> 的实例,以及test [0]是否为CommsItem的实例.

Be sure to check first if test is an instance of List<object> before casting, and if test[0] is an instance of CommsItem.

这篇关于如何处理类型"Object {System.Collections.Generic.List&lt; object&gt;}"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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