I have the following Structure within a class:
Public Structure dataStruct
Public dataPacket As List(Of Byte)
How do I efficiently use this list?
I have been trying things like:
If rxDataStruct.dataPacket IsNot Nothing Then
rxDataStruct.dataPacket.Clear()
Else
rxDataStruct.dataPacket = New List(Of Byte)
End If
or
rxDataStruct.dataPacket = New List(Of Byte) From {0}
but each of these still gives me a ‘Object reference not set to an instance of an object.’ error when I try to call:
rxDataStruct.dataPacket.Add(BytePacket)
You need to initialize the
dataPacketmember when creating adataStructinstance.Note this would be much better if you used a
Classinstead ofStructurehere. With aClassyou can guarantee thedataPacketmember is initialized for all instances by using a field initializer.