VBNet:类中项目的列表,我不能更改单个项目的值



我的问题:我有一个班级和其他班级的列表:

Public Class Signal_Type_Read
Private c_signal_count As Integer = 0  ' counter for read signals
Private _items As List(Of Signal_Item)
Private item As New Signal_Item
Sub add_sig()
c_signal_count += 1
items.Add(item)
End Sub
Public Property items() As List(Of Signal_Item)
Get
Return _items
End Get
Set(value As List(Of Signal_Item))
_items = value
End Set
End Property
Function item_counter() As Integer
item_counter = c_signal_count
End Function
Public Sub New()
_items = New List(Of Signal_Item)
End Sub
End Class
Public Class Signal_Item

Private _original_name As String
Public Property Original_name() As String
Get
Return _original_name
End Get
Set(value As String)
_original_name = value
End Set
End Property
'Many other properties
End Class

我的问题是当我在循环中使用时

Public Shared ReadSignals As New Signal_Type_Read 
//Part of a Loop to read cells values and store in the variable
ReadSignals.add_sig()
Dim c_index As Integer = ReadSignals.item_counter - 1                   
ReadSignals.items.item(c_index).Original_name = c_row.Cells(e_Signame).Value

它总是更改我的变量的所有项中的"Original_name"属性。我的错误在哪里?我只想更改oe项目。

我找到了问题的原因。。。我需要在我的ADD_sig((子中创建一个新的项目实例

Sub add_sig()
Dim s_item As New Signal_Item
c_signal_count += 1
items.Add(s_item)
End Sub

相关内容

  • 没有找到相关文章

最新更新