
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What are obsolete attributes in C#?
If a method has an obsolete attribute, then the compiler issues a warning in the code after it is compiled.
When a new method is being used in a class and if you still want to retain the old method in the class, you may mark it as obsolete by displaying a message the new method should be used, instead of the old method.
The following is an example showing how obsolete attribute is used −
using System; public class Demo { [Obsolete("Old Method shouldn't be used! Use New Method instead", true)] static void OldMethod() { Console.WriteLine("This is the old method!"); } static void NewMethod() { Console.WriteLine("This is the new method!"); } public static void Main() { OldMethod(); } }
As we have set the warning message above, it will show the following warning −
Compilation failed: 1 error(s), 0 warnings error CS0619: `Demo.OldMethod()' is obsolete: `Old Method shouldn't be used! Use New Method instead'
- Related Articles
- What are conditional attributes in C#?
- What are predefined attributes in C#?
- What are the attributes in C#?
- What are event attributes in jQuery?
- What are built-in class attributes in Python?
- What are the DataTransfer object attributes?
- attributes in C++
- Information for obsolete functions in SAP ABAP
- What are the methods in jQuery to manipulate attributes?
- What are various attributes Of page directive in JSP?
- What are the attributes of a file object in Python?
- What are the attributes of programming languages in compiler design?
- What are the attributes of a secure network in information security?
- What are the attributes of a Perfect Capital Market?
- Accessing Attributes and Methods in C#

Advertisements