Delegate with ref parameter
问题 Is there any way to maintain the same functionality in the code below, but without having to create the delegate? I'm interfacing with a 3rd-party API that contains a number of various DeleteSomethingX(ref IntPtr ptr) methods and I'm trying to centralize the code for the IntPtr.Zero check. private void delegate CleanupDelegate(ref IntPtr ptr); ... private void Cleanup(ref IntPtr ptr, CleanupDelegate cleanup) { if (ptr != IntPtr.Zero) { cleanup(ref ptr); } } 回答1: If you mean without declaring