C#, default parameter value for an IntPtr

前端 未结 2 1923
你的背包
你的背包 2020-12-07 00:28

I\'d like to use a default parameter value of IntPtr.Zero in a function that takes an IntPtr as an argument. This is not possible as IntPtr.Zero is

2条回答
  •  天命终不由人
    2020-12-07 01:03

    Since IntPtr is a struct, you could use Nullable-of-T?

    static void SomeMethod(IntPtr? ptr = null) {
        var actualPtr = ptr ?? IntPtr.Zero;
        //...
     }
    

提交回复
热议问题