public void RetireHenchman()
{
var disposableMinion = Minion as IDisposable;
if (disposableMinion != null)
disposableMinion.Dispose();
Minion = null;
}
The null coalescing operator can make this code more concise as well:
public void RetireHenchman()
{
(Minion as IDisposable)?.Dispose();
Minion = null;
}
Monday, August 22, 2016
C# Simplify Dispose Object
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment