如何手动处理非托管资源?

Arp*_*wal 4 c# unmanagedresources

我正在使用一些非托管代码,如 -

 [DllImport("wininet.dll")]
    private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
    //Creating a function that uses the API function...
    public static bool IsConnectedToInternet() {
        int Desc;
        return InternetGetConnectedState(out Desc, 0);
    }
Run Code Online (Sandbox Code Playgroud)

关于在调用Dispose时如何处理/清理这个extern静态对象的任何建议?

Wil*_*ean 5

您认为"外部静态对象"根本不是对象,它只是编译器/运行时关于如何在DLL中查找函数的一组指令.

正如桑德所说,没有什么可以清理的.