How can I deterministically dispose of a managed C++/CLI object from C#?

后端 未结 3 1321
南笙
南笙 2021-02-19 07:26

I have a managed object in a C++/CLI assembly. Being C++/CLI, it implements the Disposable pattern through its \"destructor\" (yes, I\'m aware it\'s not the same as a standard C

3条回答
  •  被撕碎了的回忆
    2021-02-19 08:12

    The C++/CLI destructor-like syntax automatically implements IDisposable, but it does so in a manner similar to C#'s explicit interface implementation. This means you'll have to cast to IDisposable to access the Dispose method:

    ((IDisposable)obj).Dispose();
    

提交回复
热议问题