c# - WPF Convert Checkbox.IsChecked to int or string 1 or 0 -


so winforms easy this:

streamwriter.writeline(this.checkbox1.checked ? "1" : "0"); 

but how can in wpf ? have use ".ischecked" , message, can't convert bool? bool.

i tried:

streamwriter.writeline(this.checkbox1.ischecked ? "1" : "0"); 

which doesn't work.

in wpf checkbox.ischecked of nullable type. have modify code to:

streamwriter.writeline((this.checkbox1.ischecked == true) ? "1" : "0"); 

note: if see ? after datatype like: bool? abc, means abc can have null value, when default bool variable not accept null value.

examples:

for int datatype:

int variable = 0; //correct int variable = null; //incorrect int? variable = null; //correct int? variable = 1; //correct 

for bool datatype:

bool mybool = false; //correct bool mybool = null; //incorrect bool? mybool = null; //correct bool? mybool = true; //correct 

also in bool? mybool = true; , int? variable = 1;, if further want retrieve values of these variable proper bool or int, have convert them using convert.toboolean, convert.toint32 respectively.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -