
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- What are conditional attributes in C#?
- What are predefined attributes in C#?
- What are the attributes in C#?
- What are Python function attributes?
- What are event attributes in jQuery?
- What are the DataTransfer object attributes?
- What are built-in class attributes in Python?
- attributes in C++
- What are the methods in jQuery to manipulate attributes?
- What are various attributes Of page directive in JSP?
- Information for obsolete functions in SAP ABAP
- 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 Perfect Capital Market?
- What are the attributes of a secure network in information security?
Advertisements