Skip to main content
Post Made Community Wiki by ChrisF
edited body
Source Link
Jonathan Wood
  • 68.1k
  • 86
  • 308
  • 542

It means your code used an object reference variable that was set to null (i.e. it did not reference an actual object instance).

To prevent the error, objects that could be null should be tested for null before being used.

if (myvar != null)
{
    // Go ahead and use myvar
    myvar.property = ...
}
else
{
    // Whoops! myvar is null and cannot be used without first
    // assigning it to an instance reference to it
    // Attempting to use myvar here will result in NullReferenceException
}

It means your code used an object reference variable that was set to null (i.e. it did not reference an actual object instance).

To prevent the error, objects that could be null should be tested for null before being used.

if (myvar != null)
{
    // Go ahead and use myvar
    myvar.property = ...
}
else
{
    // Whoops! myvar is null and cannot be used without first
    // assigning an instance reference to it
    // Attempting to use myvar here will result in NullReferenceException
}

It means your code used an object reference variable that was set to null (i.e. it did not reference an actual object instance).

To prevent the error, objects that could be null should be tested for null before being used.

if (myvar != null)
{
    // Go ahead and use myvar
    myvar.property = ...
}
else
{
    // Whoops! myvar is null and cannot be used without first
    // assigning it to an instance reference
    // Attempting to use myvar here will result in NullReferenceException
}
added 335 characters in body
Source Link
Jonathan Wood
  • 68.1k
  • 86
  • 308
  • 542

It means your code used an object reference variable that was set to null (i.e. it did not refer toreference an actual object instance).

To prevent the error, objects that could be null should be tested for null before being used.

if (myvar != null)
{
    // Go ahead and use myvar
    myvar.property = ...
}
else
{
    // Whoops! myvar is null and cannot be used without first
    // assigning an instance reference to it
    // Attempting to use myvar here will result in NullReferenceException
}

It means your code used an object reference that was set to null (i.e. it did not refer to an actual object instance).

To prevent the error, objects that could be null should be tested for null before being used.

It means your code used an object reference variable that was set to null (i.e. it did not reference an actual object instance).

To prevent the error, objects that could be null should be tested for null before being used.

if (myvar != null)
{
    // Go ahead and use myvar
    myvar.property = ...
}
else
{
    // Whoops! myvar is null and cannot be used without first
    // assigning an instance reference to it
    // Attempting to use myvar here will result in NullReferenceException
}
References are null, not objects. "... object set to null .." is a misnomer.
Source Link

It means your code used an object reference that was set to null (i.e. it did not refer to an actual object instance).

To prevent the error, objects that could be null should be tested for null before being used.

It means your code used an object that was set to null (i.e. it did not refer to an actual object instance).

To prevent the error, objects that could be null should be tested for null before being used.

It means your code used an object reference that was set to null (i.e. it did not refer to an actual object instance).

To prevent the error, objects that could be null should be tested for null before being used.

Source Link
Jonathan Wood
  • 68.1k
  • 86
  • 308
  • 542
Loading