Using Obsolete Attribute in C# .NET

person Jason Huangfolder_open.NET, C#, Codelocal_offer, , , access_time May 13, 2015

C# has a built-in attribute that you can apply to any type in your C# code to designate a method as obsolete.

To do that, before your method declaration, simply put in the [Obsolete] Attribute.

For example:

private void testfunction()
   //some code here

After you set this attribute in your code, every time you compile, it would give you the warning if you set the warning level high. Intelli-sense would also show a little tool tip to warn you that this function is obsolete.











This is useful for transitioning old code to newer code.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>