[英]Delete a record from an array VB.NET
I'm trying to delete a record from an array in VB.Net
but I can never get it to delete the correct one 我正在尝试从
VB.Net
的数组中删除记录,但是我永远无法获取它来删除正确的记录
In my code, intPosition
is the position where the desired record I want to delete is. 在我的代码中,
intPosition
是我要删除的所需记录所在的位置。 Customers
is the name of the 3D array and NumberOfCustomers
can be treated as the size of the array. Customers
是3D数组的名称, NumberOfCustomers
可以视为数组的大小。
If MsgBox("Are you sure you want to delete this record?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
NumberOfCustomers -= 1
For i = intPosition + 1 To NumberOfCustomers
Customers(i - 1) = Customers(i)
Next
NumberOfCustomers -= 1
ReDim Preserve Customers(NumberOfCustomers)
Call SaveCustomer()
End If
Please could someone amend or find similar code for this in VB.NET
. 请有人修改或在
VB.NET
找到类似的代码。
Thanks 谢谢
I would propose you do without the array as it's extremely inefficient for operations like this. 我建议您不要使用数组,因为这样的操作效率极低。 Instead, you should use one of the built-in classes like
List(Of T)
which is much better suited for how you're trying to use it. 相反,您应该使用诸如
List(Of T)
类的内置类之一,它更适合您尝试使用它的方式。
Dim customers = New List(Of Customer)
'populate your list however you do it.
If MsgBox("Are you sure you want to delete this record?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
customers.RemoveAt(position)
End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.