❔ Null instance in Array of Classes
Hey guys. It's my first time here, so sorry for any formatting errors or something like that.
I'm making this program where I need to create an array of objects of a class. The compiler doesn't detect any errors, but when I try to modify an instance in the array he tells me that that instance is null.
6 Replies
yes that's how it works. read on reference types
the default value for a reference type is null
and how would I define the value for all instances of the array here?
When you new up an array you get an array of the default value
The default value of a class (aka reference type) is null
So you need to go through the array and initialize
Foo being Card here
What you are doing now is accessing something on null, not valid
oh, think I got it
let me try this
this worked perfectly!!
Also got how it works
Thank you so much @mrphil2105 !!
👍
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.