Missing Class

Represents a missing Object. This class cannot be inherited.


Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

public sealed class Missing

The Missing type exposes the following members.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Public fieldStatic memberValueRepresents the sole instance of the Missing class.

Missing is used to invoke a method with a default argument.

Only one instance of Missing ever exists.

The following example shows how to use Missing to invoke a method with a default argument with late binding.

To run this example, first see Building examples that have static TextBlock controls for Windows Phone 8. Once you have created an application project, you must include the following Visual Basic code. For a Visual Basic application, add the code to your project as a new class. For a C# application, add a Visual Basic class library project, and create a reference to this project from your C# project.

Public Class MissingSample
    Public Shared Function MyMethod(Optional k As Integer = 33) As String
        Return "k = " & k.ToString()
    End Function

End Class

The C# code in this example assumes that the Visual Basic class library project is named MyLibrary; if you name it something else you must change the namespace that is shown in the argument of the GetMethod method.

Visual Basic code is used for the MissingSample class because C# does not support optional parameters in managed code. Optional parameters are not part of the Common Language Specification (CLS). Therefore, code that uses optional parameters is not CLS-compliant. For more information, see the Common Language Specification and Writing CLS-Compliant Code in the .NET Framework documentation.

using System;
using System.Reflection;

class Example
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
      // To invoke MyMethod with the default argument value, pass 
      // Missing.Value for the optional parameter. First, get the 
      // method.
      MethodInfo mi = 

      // Second, create an array of parameters and invoke the method.
      // In this case, the array contains just one element.
      object result = mi.Invoke(null, new Object[] { Missing.Value });

      outputBlock.Text += String.Format("MyMethod returned '{0}'\n", result);

/* This code example produces the following output:

MyMethod returned 'k = 33'

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

© 2015 Microsoft