急,动态判断数组类型

webzt 2008-07-11 12:10:03
有一个时间数组
public DateTime[] datetimearray = new DateTime[2];
通过反射获得对象引用,如下,这没问题
System.Reflection.FieldInfo field = this.GetType().GetField("datetimearray");
Object DateTimeRef=((DateTime[])field.GetValue(this))[0];
但如果我只知道字段名(datetimearray),但不知道这个数组的类型,则Object DateTimeRef=((DateTime[])field.GetValue(this))[0];
这段语句该怎么修改我写的是Object DateTimeRef=((Object[])field.GetValue(this))[0];运行时通不过
...全文
77 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
webzt 2008-07-11
  • 打赏
  • 举报
回复
结贴了
webzt 2008-07-11
  • 打赏
  • 举报
回复
就是这样的谢谢了
vwxyzh 2008-07-11
  • 打赏
  • 举报
回复
值类型数组无法转换成object[]
这时候可以使用所有数组的基类Array
object DateTimeRef = ((Array)field.GetValue(this)).GetValue(0);
webzt 2008-07-11
  • 打赏
  • 举报
回复
各位高手帮帮忙

110,024

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧