When trying to dispose of a UdpClient, I found that it's impossible. For the following:
UdpClient udpClient = new UdpClient();
udpClient.Dispose();
Visual Studio shows an error:
'System.Net.Sockets.UdpClient.Dispose(bool)' is inaccessible due to its protection level
Does this mean that I should inherit from UdpClient
and expose the Dispose
(Since it seems to be the consensus that whatever implements IDisposable should be disposed of)? Is there some reason we shouldn't use the class directly? Or is there simply nothing to dispose of after calling Close
?
Though a using
statement does work - it's not suitable when listening.
protected virtual void UdpClient.Dispose(Boolean)
has been around since .NET framework 2.0 whereas the parameter-less overloadpublic void Dispose()
is only available since 4.6. Your project is targeting framework < 4.6 so you only see the protected method – Meaghanmeagher