最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.NET数组与下界> 0

SEO心得admin67浏览0评论
本文介绍了.NET数组与下界> 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

尽管也许bizare事情想做的事情,我需要建立在中的阵列,下限> 0,这起初似乎是可能的,使用:

Although perhaps a bizare thing to want to do, I need to create an Array in .Net with a lower bound > 0. This at first seems to be possible, using:

Array.CreateInstance(typeof(Object), new int[] {2}, new int[] {9});

生成所期望的结果(对象具有下界集到9的阵列)。但是,创建数组实例不能再传递到其他的方法希望对象[] 给我一个错误,说:

Produces the desired results (an array of objects with a lower bound set to 9). However the created array instance can no longer be passed to other methods expecting Object[] giving me an error saying that:

System.Object的[*] 不能转换成 System.Object的[] 。什么是数组类型这种差异,我怎么能解决这个?

System.Object[*] can not be cast into a System.Object[]. What is this difference in array types and how can I overcome this?

编辑:测试code =

test code =

Object x = Array.CreateInstance(typeof(Object), new int[] {2}, new int[] {9}); Object[] y = (Object[])x;

其中失败,:无法转换类型的对象System.Object的[*]'输入'System.Object的[]'

Which fails with: "Unable to cast object of type 'System.Object[*]' to type 'System.Object[]'."

我也想指出,这种做法的使用多个维度什么时候工作

I would also like to note that this approach DOES work when using multiple dimensions:

Object x = Array.CreateInstance(typeof(Object), new int[] {2,2}, new int[] {9,9}); Object[,] y = (Object[,])x;

,工作正常。

Which works fine.

推荐答案

这篇文章解释它: HTTP ://www.panopticoncentral/articles/950.aspx

发布评论

评论列表(0)

  1. 暂无评论