2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[小ネタ] IntPtr型の省略可能引数には、default(IntPtr)を使う

Last updated at Posted at 2019-07-23

タイトル通りです。

IntPtr型の省略可能引数を定義するときは、

public void ExampleMethod(IntPtr param = new IntPtr()){}

もしくは

public void ExampleMethod(IntPtr param = default(IntPtr)){}

と書く。

規定値をIntPtr.Zeroと書きたくなるが、
error CS1736: param' の既定のパラメーター値は、コンパイル時の定数である必要があります。
というコンパイルエラーになります。

詳しくは 省略可能な引数を見てください。

2
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?