What does “Object reference not set to an instance

2018-12-31 08:37发布

This question already has an answer here:

I am receiving this error and I'm not sure what it means?

Object reference not set to an instance of an object.

8条回答
长期被迫恋爱
2楼-- · 2018-12-31 09:19

Another easy way to get this:

 Person myPet = GetPersonFromDatabase();
 // check for myPet == null... AND for myPet.PetType == null
 if ( myPet.PetType == "cat" ) <--- fall down go boom!
查看更多
墨雨无痕
3楼-- · 2018-12-31 09:19

what does this error mean? Object reference not set to an instance of an object.

exactly what it says, you are trying to use a null object as if it was a properly referenced object.

查看更多
登录 后发表回答