在 C# 中的任意起始索引上初始化数组 [英] Initializing an array on arbitrary starting index in c#
问题描述
是否可以在 C# 中初始化数组,例如,子索引 1?
Is it possible in c# to initialize an array in, for example, subindex 1?
我正在使用 Office 互操作,每个属性都是一个以 1 开头的对象数组(我假设它最初是在 VB.NET 中编写的),并且您无法修改它,您必须为它设置整个数组接受更改.
I'm working with Office interop, and every property is an object array that starts in 1 (I assume it was originally programed in VB.NET), and you cannot modify it, you have to set the entire array for it to accept the changes.
作为一种解决方法,我克隆原始数组,修改该数组,并在完成后将其设置为一个整体.
As a workaround I am cloning the original array, modifying that one, and setting it as a whole when I'm done.
但是,我想知道是否可以创建一个新的基于非零的数组
But, I was wondering if it was possible to create a new non-zero based array
推荐答案
您可以使用 Array.CreateInstance
.
You can use Array.CreateInstance
.
请参阅.NET 中的数组类型
这篇关于在 C# 中的任意起始索引上初始化数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!