Namespace:
System
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
Dim instance As New ObsoleteAttribute()
public ObsoleteAttribute()
public:
ObsoleteAttribute()
public function ObsoleteAttribute()
The following table shows the initial property values for an instance of ObsoleteAttribute.
Property | Value |
|---|
IsError |
false |
Message |
nullNothingnullptra null reference (Nothing in Visual Basic) |
The following example demonstrates the ObsoleteAttribute() constructor. It contains a function which calls a method that has been designated as obsolete, and then attempts to catch an exception using a try/catch block.
using System;
public class ObsoleteAttrib_Cons1
{
// Mark the method as 'Obsolete'.
[ObsoleteAttribute()]
public string OldFunction()
{
return "This is the String from old function.";
}
// Create the another function which is replacement to the 'OldFunction'.
public string NewFunction()
{
return "This is the String from new function.";
}
}
public class TestObsolete1
{
static void Main(string[] args)
{
try
{
ObsoleteAttrib_Cons1 myObsolete = new ObsoleteAttrib_Cons1();
Console.WriteLine(myObsolete.OldFunction());
}
catch(Exception e)
{
Console.WriteLine("The Exception is :"+e.Message);
}
}
}
using namespace System;
public ref class ObsoleteAttrib_Cons1
{
public:
// Mark the method as 'Obsolete'.
[Obsolete]
String^ OldFunction()
{
return "This is the String from old function.";
}
// Create the another function which is replacement to the 'OldFunction'->
String^ NewFunction()
{
return "This is the String from new function.";
}
};
int main()
{
try
{
ObsoleteAttrib_Cons1^ myObsolete = gcnew ObsoleteAttrib_Cons1;
Console::WriteLine( myObsolete->OldFunction() );
}
catch ( Exception^ e )
{
Console::WriteLine( "The Exception is : {0}", e->Message );
}
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 3.5, 2.0, 1.0
XNA Framework
Supported in: 3.0, 2.0, 1.0
Reference