Missing Class
Assembly: mscorlib (in mscorlib.dll)
'Declaration <SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public NotInheritable Class Missing Implements ISerializable 'Usage Dim instance As Missing
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ public final class Missing implements ISerializable
SerializableAttribute ComVisibleAttribute(true) public final class Missing implements ISerializable
Not applicable.
The following example shows how to use Missing to invoke a method with a default argument. To compile and run this code example, you must first compile the following Visual Basic code as a DLL assembly named Target.dll. Save the code as Target.vb. From the command line, use vbc /t:library Target.vb to compile the assembly.
Imports System
Public Class MissingSample
Public Shared Sub MyMethod(Optional k As Integer = 33)
Console.WriteLine("k = " & k.ToString())
End Sub
End Class
If you compile Target.dll in Visual Studio, by default the project name is used as the name of a namespace that contains the MissingSample class. Either remove the namespace from the Target project, or add a using Target; statement to the C# code (Imports Target in Visual Basic, using namespace Target; in Visual C++).
Note: |
|---|
| Visual Basic code is used for Target.dll because C# and Visual C++ do not support optional parameters in managed code. Optional parameters are not part of the Common Language Specification. Therefore, code that uses optional parameters is not CLS-compliant. For more information, see Writing CLS-Compliant Code. |
When you compile the Visual Basic and C# versions of this code example, add references to Target.dll. For example, if you are compiling from the command line, use the /r:Target.dll option. The Visual C++ version of the code example already includes a #using statement for Target.dll.
Imports System Imports System.Reflection Imports Microsoft.VisualBasic Public Class MissingSample Shared Sub Main() 'To invoke MyMethod with a default argument, use the following syntax: GetType(MissingSample).GetMethod("MyMethod").Invoke(Nothing, New Object() {Missing.Value}) End Sub Shared Function MyMethod(Optional k As Integer = 33) As Integer Console.WriteLine("k = " & k.ToString()) Return 0 End Function End Class
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Note: