Export (0) Print
Expand All

Missing Class

Represents a missing Object. This class cannot be inherited.

System.Object
  System.Reflection.Missing

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

[ComVisibleAttribute(true)]
public sealed class Missing

The Missing type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Equals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360FinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ValueRepresents the sole instance of the Missing class.
Top

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 Use a Demo Method and a TextBlock Control. Once you have created a Silverlight application project, you must include the following Visual Basic code. For a Visual Basic Silverlight-based application, add the code to your project as a new class. For a C# Silverlight-based application, add a Visual Basic Silverlight 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
NoteNote:

The C# code in this example assumes that the Visual Basic class library project is named SilverlightLibrary; 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 = 
         typeof(SilverlightLibrary.MissingSample).GetMethod("MyMethod");

      // 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'
 */


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

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

Community Additions

Show:
© 2014 Microsoft