TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to C-SHARP

C# Obsolete Attribute

Use the Obsolete attribute from the System namespace to create warnings.
Obsolete. The Obsolete attribute generates a compile-time warning. When a method has the Obsolete attribute, the C# compiler issues a warning if it is called. This helps keep programs correct. This makes it easier to transition from old methods.Attribute
To begin, the Obsolete attribute is found in the System namespace. It is an attribute type, which means you can specify the type as Obsolete or ObsoleteAttribute. The suffix "Attribute" is automatically added at compile-time.Using System

Tip: To specify an attribute, decorate a method with the declaration and surround the attribute with square brackets.

Info: You can use the Obsolete attribute with zero, one, and two arguments. This example uses one argument. It generates a compile-time warning.

C# program that uses Obsolete attribute using System; class Program { static void Main() { MethodA(); } [Obsolete("Use MethodB instead")] static void MethodA() { } } Output ... warning CS0618: 'Program.MethodA()' is obsolete: 'Use MethodB instead'
Attributes are invoked the same way as constructors. The Obsolete attribute can have zero arguments. In this case, a generic compile-time warning is generated. It can have one argument—a specific warning is generated.

Finally: It can instead have two arguments. The compilation fails if you specify true as the second argument.

Summary. Obsolete is useful for versioning. If you have developed a new control flow and a certain method is no longer wanted, you can decorate it with the Obsolete attribute, and then correct warnings or errors as you go along.

And: In larger projects this can help coordinate the methods different programmers employ.

© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf