Mono Class Library: System NamespaceSystem.NullReferenceException Class |
See Also: NullReferenceException Members
System.Object
System.Exception
System.SystemException
System.NullReferenceException
|
All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.
Note:[Edit]Applications throw the ArgumentNullException rather than NullReferenceException .
The following CIL instructions throw NullReferenceException :
- callvirt
- cpblk
- cpobj
- ldelema
- ldelem.<type>
- ldfld
- ldflda
- ldind.<type>
- ldlen
- stelem.<type>
- stind.<type>
- stfld
- throw
- unbox
- initblk
The following example demonstrates an error that causes a NullReferenceException exception.
C# Example using System; public class Ints { public int[] myInts; } public class NullRefExample { public static void Main() { Ints ints = new Ints(); try { int i = ints.myInts[0]; } catch( NullReferenceException e ) { Console.WriteLine( "Caught error: {0}.", e); } } }The output is
Example Caught error: System.NullReferenceException: Object reference not set to an instance of an object. at NullRefExample.Main().
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0