✅ Object reference not set to an instance of an object?
I keep getting a run-time error of
Object reference not set to an instance of an object
on line int index = rand.Next(0, Names.Count);
and I'm not sure why.5 Replies
process of elimination
of the things on that line, what could possibly be null?
i'm confused because this code doesn't compile to begin with
you initialize random
rand
and it can't be null because you don't modify it anywhere, so you exclude that.
then only thing that is left being Names
make sure that is not null.
$debugTutorial: Debug C# code and inspect data - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
Learn to use the debugger, it's the absolute most important tool a developer could have.
I do use the debugger. I spend x amount of time on error's before I even come here to ask for help. I try and solve them first through my own research, trial, and error.