I have the following
Public Structure Foo
dim i as integer
End Structure
Public Class Bar
Public Property MyFoo as Foo
Get
return Foo
End Get
Set(ByVal value as Foo)
foo = value
End Set
dim foo as Foo
End Class
Public Class Other
Public Sub SomeFunc()
dim B as New Bar()
B.MyFoo = new Foo()
B.MyFoo.i = 14 'Expression is a value and therefore cannot be the target of an assignment ???
End Sub
End Class
My question is, why can I not assign to i through my property in the Bar class? What have I done wrong?
The answer is found here, it says the following:
This is because the struct is only a temporary variable. So the solution is to create a new struct of the type you need, assign it all it’s internal variables and then assign that struct to the struct property of the class.