Missing Class
Represents a missing Object. This class cannot be inherited.
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
The Missing type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() ![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() ![]() ![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() ![]() ![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() ![]() ![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() ![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() ![]() ![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
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
Note: |
|---|
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.
Imports System.Reflection Public Class MissingSample Public Shared Function MyMethod(Optional k As Integer = 33) As String Return "k = " & k.ToString() End Function End Class Public Class Example Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) ' To invoke MyMethod with the default argument value, pass ' Missing.Value for the optional parameter. First, get the ' method. Dim mi As MethodInfo = GetType(MissingSample).GetMethod("MyMethod") ' Second, create an array of parameters to pass to the method. ' In this case, the array contains just one element. Dim arguments() As Object = { Missing.Value } ' Finally, invoke the method. Specify Nothing for the target ' object, because the method is Shared. Dim result As Object = mi.Invoke(Nothing, arguments) outputBlock.Text &= String.Format("MyMethod returned '{0}'" & vbLf, result) End Sub End Class ' This code example produces the following output: ' 'MyMethod returned 'k = 33'
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.






Note: