web analytics
Marking a method as Obsolete/Deprecated in C# Options
codeling
Posted: Thursday, October 5, 2017 2:31:06 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 919
Points: 3861

The following C# code shows you how to use the Obsolete attribute to mark members and or types as obsolete. 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.

[Obsolete("Use Dispose() instead")]

public void Close()

{

  Dispose();

}

Sponsor
Posted: Thursday, October 5, 2017 2:31:06 PM
 
codeling
Posted: Thursday, October 5, 2017 2:34:24 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 919
Points: 3861

Adding a true value as second parameter, you can also cause the compilation to fail  instead of warning if the method is called from somewhere in code.

[Obsolete("Use Dispose() instead"), true]

public void Close()

{

  Dispose();

}

Users browsing this topic
Guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.


© 2017 Digcode.com. All rights reserved.