
Grigor Samvelian
2,852 PointsDon't understand why System.NullReferenceException will get thrown
What will happen when the following code runs?
Map map; int area = map.Width * map.Height;
could someone please explain why the NullReferenceException gets thrown here?
1 Answer

John Lack-Wilson
8,159 PointsNull Reference Exception is thrown when you are attempting to use something that is null.
It seems to me that you are trying to assign area with values that do not yet exist because you have not assigned Map map to anything.
You should assign Map map to something.
Grigor Samvelian
2,852 PointsGrigor Samvelian
2,852 Pointsah ok. Wasn't coding just doing a quiz and got held up on this question. Thank you you really cleared things up.