ShowDialog return type: form against window

In WPF / .Net, both System.Windows.Windowand System.Windows.Forms.Formhave the method .ShowDialog.

The difference is that the version Windows.Windowreturns a nullable bool ( bool?or Nullable<bool>), and the version Forms.Formreturns a straight line bool.

I have not seen the nullable bool ever be null, and cannot find a case where it will be in the MSDN documentation.

Can anyone explain why it Windows.Window.ShowDialogreturns NULL? Should I check this out? What does it mean if I see null?

+3
source share
4 answers

see here: Window.DialogResult Property

DialogResult is null when a dialog is displayed, but is not accepted or canceled.

+2

, , DialogResult false, non-dialog null DialogResult

, Windows.Window.ShowDialog nullable, DialogResult, null,

+1

Windows.Window.ShowDialog ?

, . , , nullable bool , , . , .

0

ShowDialog returns the DialogResult dialog box, which is Nullable. While the window is open, DialogResult is null. If the DialogResult parameter is set to true or false, ShowDialog will return this result. Since any closed operation in the window will implicitly set DialogResult to false if this is not explicitly set, yes, you can safely ignore the null values ​​returned by ShowDialog (on the other hand, DialogResult can be empty if you check it directly). This is just the result of type matching as far as I know.

0
source

Source: https://habr.com/ru/post/1790823/


All Articles