0
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 5 years have passed since last update.

Visual Studio / WPF > C# > bool? | Nullable<bool>: NULL許容型

Last updated at Posted at 2017-04-26
動作環境
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2

http://gushwell.ldblog.jp/archives/52334178.html
のコードを見ていて、以下の記述が気になった。

bool? result = openFileDialog.ShowDialog();

boolの後ろに?がついている。
これは
https://msdn.microsoft.com/ja-jp/library/bb384091.aspx
によると

Null 許容 bool? 型

というものらしい。

Null許容型の記事は過去に書いている。
http://qiita.com/7of9/items/8eb2acca99db19c4193f

MSDNのページではbool?でなく下記のような記載を使っている。
こちらの方がコードの可読性が高いように思う。
https://msdn.microsoft.com/ja-jp/library/microsoft.win32.savefiledialog(v=vs.110).aspx

Nullable<bool> result = dlg.ShowDialog();

0
1
0

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
0
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?