ObsoleteAttribute.ObsoleteAttribute(String) Constructor

Initializes a new instance of the ObsoleteAttribute class with a specified workaround message.

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

Public Sub New ( _
	message As String _
Dim message As String

Dim instance As New ObsoleteAttribute(message)
public ObsoleteAttribute (
	String message
public function ObsoleteAttribute (
	message : String
Not applicable.



The text string that describes alternative workarounds.

The following table shows the initial property values for an instance of ObsoleteAttribute.






The workaround message.

The following example demonstrates the ObsoleteAttribute(String) constructor. It contains a function which calls a method that has been designated as obsolete, then attempts to catch an exception using a try/catch block.The parameter string is displayed as a workaround message.

Imports System

Public Class ObsoleteAttrib_Cons1
   ' Mark the method as 'Obsolete' with message as parameter.
   <ObsoleteAttribute("This function will be removed from future Versions.Use another function 'NewFunction'")> _
   Public Function OldFunction() As String
      OldFunction= "This is the String from old function."
   End Function 'OldFunction

   ' Create the another function which is replacement to the 'OldFunction'.
   Public Function NewFunction() As String
      NewFunction= "This is the String from new function."
   End Function 'NewFunction
End Class 'ObsoleteAttrib_Cons1

Public Class TestObsolete2
   'Entry point which delegates to C-style main Private Function
   Public Overloads Shared Sub Main()
   End Sub
   Overloads Shared Sub Main(args() As String)
         Dim myObsolete As New ObsoleteAttrib_Cons1()
      Catch e As Exception
         Console.WriteLine(("The Exception is :" + e.Message))
      End Try
   End Sub 'Main
End Class 'TestObsolete2

import System.*;

public class ObsoleteAttrib_Cons1
    // Mark the method as 'Obsolete' with message as parameter.

    /** @attribute ObsoleteAttribute("This function will be removed from future"
        + "Versions.Use another function 'NewFunction'")
    public String OldFunction()
        return "This is the String from old function.";
    } //OldFunction

    // Create the another function which is replacement to the 'OldFunction'.
    public String NewFunction()
        return "This is the String from new function.";
    } //NewFunction
} //ObsoleteAttrib_Cons1

public class TestObsolete2
    public static void main(String[] args)
        try {
            ObsoleteAttrib_Cons1 myObsolete = new ObsoleteAttrib_Cons1();
        catch (System.Exception e) {
            Console.WriteLine("The Exception is :" + e.get_Message());
    } //main
} //TestObsolete2

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.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0