C#, default parameter value for an IntPtr

前端 未结 2 1914
你的背包
你的背包 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条回答
  •  -上瘾入骨i
    2020-12-07 01:16

    Somewhat unintuitive, to put it mildly, you get it by using the new operator:

        void Foo(IntPtr arg = new IntPtr()) { 
        }
    

    That was for fun, you probably enjoy this one better:

        void Foo(IntPtr arg = default(IntPtr)) { 
        }
    

提交回复
热议问题