Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET创建项/将项添加到自定义对象数组_Asp.net - Fatal编程技术网

ASP.NET创建项/将项添加到自定义对象数组

ASP.NET创建项/将项添加到自定义对象数组,asp.net,Asp.net,i、 e.如果我正在创建这样的数组 Dim webLinesArray() As OrderService.webdirect_WebLinesRow 如何将项目添加到此数组,即我希望添加这样的项目 Dim webLine As New OrderService.webdirect_WebLinesRow webLine.OrderQty = quantity webLine.ProductCode = produ

i、 e.如果我正在创建这样的数组

        Dim webLinesArray() As OrderService.webdirect_WebLinesRow
如何将项目添加到此数组,即我希望添加这样的项目

Dim webLine As New OrderService.webdirect_WebLinesRow
                webLine.OrderQty = quantity
                webLine.ProductCode = productId
                webLine.LineNumber = 1
                webLinesArray.add or something (webLine)
就在最后一行,我不知道如何将项目添加到数组中(1)您不能将项目添加到数组中(它们的长度是固定的) 2) 但是,可以为数组中的某个位置赋值(webLinesArray()=foo)


你有问题。如果想使用一个列表,我想,它将允许您动态添加项,并且其行为与数组类似(从用户/程序员的角度来看)

对于基本数组,您必须调整其大小,然后将项分配到数组中的索引中,我认为基本数组没有添加项

Array.Resize(webLinesArray, Newsize)
webLinesArray(index) = Item

您必须重新分配阵列:

ReDim Preserve webLinesArray(webLinesArray.Length+1)
Now you can store the element at the last position. 

Preserve关键字用于保存数组中的现有值

我同意,我几乎不再使用数组,我总是使用List(of T)是的,我看到的唯一问题是它需要动态大小,因为我不知道大小beforehand@StevieB如果是这样的话,是什么阻止你使用列表(T)?这是动态的,有一个“Add”方法。在API中,它看起来就像我传递给它的函数中的一个数组,它作为一个参数寻找。例如,作为webdirect的ByVal WebLines()_WebLinesRow@StevieB如果API需要,您仍然可以使用List(of T)并在列表上调用ToArray()方法。方法将(T的)列表转换为T的本机数组。