web analytics

Marking a method as Obsolete/Deprecated in C#

Options

codeling 1595 - 6639
@2017-10-05 14:31:06

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();

}

@2017-10-05 14:34:24

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();

}

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com