0
存储对象这里是我的代码示例输出,一个简单的聊天程序:问题与在字典
John says: Hello there!
Marsha says: Hi there!
John says: First sentence.
Marsha says: Second Sentence.
在TextBox控件,它看起来像以上。然而,在使用的字典中存储的谈话,这将是这样的:
John says: First sentence.
Marsha says: Hi there!
John says: First sentence.
Marsha says: Second sentence.
我已经在我的代码几次......我的生命,我不能告诉正是我这可能会出错。
我追踪的问题到sendmsgbutton方法,这里介绍:
Private Sub sendMsgButton_Click(sender As System.Object, e As System.EventArgs) Handles sendMsgButton.Click
If rtnConnectStatus(t) = False Then
RaiseEvent statusCheck("Not Connected" + ControlChars.CrLf)
Else
Dim completeMsg As String
msg.Name = nameText.Text
msg.Message = msgTxt.Text
completeMsg = msg.ToString
msgRecorded.Text &= completeMsg
RaiseEvent statusCheck("Message Sent." + ControlChars.CrLf)
msgList.Add(msgListIndex, msg)
'RaiseEvent debugBox(msg, msgListIndex)
msgListIndex += 1
RaiseEvent DataSend(completeMsg)
msgTxt.Clear()
End If
End Sub
这里是msgList继承了字典类:
Public Class MsgDictionary
Inherits DictionaryBase
Public Property Item(ByVal key As Integer) As MsgObj
Get
Return CType(Dictionary(key), MsgObj)
End Get
Set(ByVal m As MsgObj)
Dictionary(key) = m
End Set
End Property
Public Sub Add(ByVal index As Integer, ByVal m As MsgObj)
Dictionary.Add(index, m)
End Sub
End Class
我的下一个测试是看它的只有的消息值或名称值是否也受此影响。
非常感谢您提前给予的帮助/建议。
编辑:只是为了澄清,每个字典条目的名称和字符串部分作为单个字典对象的属性。
首先,感谢您的回复。我编辑了原始回复,但我也想和你一起核对一下。字典中的每个条目都应该是每个对象中包含两个变量(名称和消息)的单个消息对象。根据你的回应,看起来这仍然适用于不管,但我想确定。 – Gith
是的,没有问题。如果您已经定义了包含两个属性(名称和消息)的特定类型/类,则可以像使用字符串一样创建一个列表;因此你会得到一个名字消息的列表。只需使用我通过用“MsgObj”替换“string”所建议的结构。 – varocarbas
最终评论如何解决这个问题,因为这个答案有助于找到额外的数据。 (这主要是针对那些发现这个问题的人,即使将数据放到一个对象中,我也发现它仍然在继续,但是,我也有我的“MsgObj”对象作为_global变量_因为字典仍然是引用那个变量,它在字典里改变和复制自己,所以我把它移到了send方法中的一个局部变量上,在确保了唯一的数据之后,所有的东西都完全按照它的意思。 – Gith