如何将对象转换为系统,collection.generic列表 [英] how to convert object into system,collection.generic list

查看:138
本文介绍了如何将对象转换为系统,collection.generic列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将对象转换为系统,collection.generic列表< string>

how to convert object into system,collection.generic list<string>

推荐答案



请点击下面的链接:
http://stackoverflow.com/Questions/1882520/unable-to-cast-object-of-type-system-collections-generic-list1item-to-type [ http://social.msdn.microsoft.com /Forums/zh-CN/csharpgeneral/thread/27626be0-25b5-40bd-847c-3d1f36ee11a7/ [
Hi,

Please follow the links bellow:
http://stackoverflow.com/questions/1882520/unable-to-cast-object-of-type-system-collections-generic-list1item-to-type[^]
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/27626be0-25b5-40bd-847c-3d1f36ee11a7/[^]

It may help you.
All the best.
--AK


转换"一词是什么意思?如果某个对象不是列表,也就是说,如果其实际的运行时类型不是列表,则无法神奇地将其设为列表.如果尝试直接转换它,它将抛出异常,因为对象的运行时类型与赋值不兼容,并且使用as运算符的动态情况将返回null.此外,应避免首先需要类型区分大小写的情况.

—SA
What to you mean by the word "convert"? If some object is not a list, that is, if its actual run-time type is not a list, you cannot magically make it a list. If your try to cast it directly, it will throw the exception is the run-time type of object is not assignment compatible, and the dynamic case using as operator will return null. Besides, you should avoid the situation where type case is required in first place.

—SA


这篇关于如何将对象转换为系统,collection.generic列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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