vb.net - Help with Class arrays -


when following executes, error 'nullreference exception' - object reference not set instance of object. testclass has , set methods integer property testword. how should following changed let me set testword in 6 elements of tarr?

dim tarr(5) testclass  integer = 0 5    tarr(i).testword = * 10 next 

you need initialize tarr array. if don't that, it's reference object doesn't exist (that's why null reference exception).

dim tarr(5) testclass <---- doesn't mean you'll have array of testclass filled instances of testclass. need assign 5 testclass instances.

you can in loop:

for integer = 0 5    tarr(i) = new testclass()    tarr(i).testword = * 10 next 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -