[C# Helper]
Index Books FAQ Contact About Rod
[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[Beginning Software Engineering]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Use the Obsolete attribute in C#

[Use the Obsolete attribute in C#]

The Obsolete attribute tells the C# IDE that a method is outdated and should no longer be used. You can include a string to display to the developer. The string usually tells what newer method to use instead of the obsolete method. You can also determine whether the IDE treats using this method as a warning or an error.

In this example, the following Allowed method is marked as obsolete but is allowed. The IDE flags the line calling the method and displays a warning in the Tasks pane, but it will compile and execute the program if it uses this method.

[Obsolete("This method will soon be discontinued. " + "Use the new version instead.", false)] private void Allowed() { }

The Obsolete attribute in the following method uses final parameter true to indicate that its use should raise an error and not be allowed. The IDE flags the line calling the method, displays an error message in the Tasks pane, and will not allow the program to run if this method is used.

[Obsolete("This method is no longer allowed. " + "Use the new version instead.", true)] private void Disallowed() { }

Download the example to experiment with it and to see additional details.

© 2009-2022 Rocky Mountain Computer Consulting, Inc. All rights reserved.