Public Structure testStruct
Dim blah as integer
Dim foo as string
Dim bar as double
End Structure
'in another file ....
Public Function blahFooBar() as Boolean
Dim tStrList as List (Of testStruct) = new List (Of testStruct)
For i as integer = 0 To 10
tStrList.Add(new testStruct)
tStrList.Item(i).blah = 1
tStrList.Item(i).foo = "Why won't I work?"
tStrList.Item(i).bar = 100.100
'last 3 lines give me error below
Next
return True
End Function
我得到的錯誤是:表達式是一個值,因此不能作爲賦值的目標。爲什麼這個結構列表不允許我爲該字段賦值?
爲什麼?
簡單的解決方案:不要使用結構,使用類? – 2012-02-15 01:16:54