Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#, default parameter value for an IntPtr

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 not a compile time constant.

Is there any way I can do what I want?

like image 800
Tom Davies Avatar asked Oct 21 '12 15:10

Tom Davies


1 Answers

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)) { 
    }
like image 142
Hans Passant Avatar answered Oct 06 '22 00:10

Hans Passant