'How do I reset a PasswordChar?

I want to make my PasswordChar in a box empty when a user clicks a button (so they can confirm they wrote it right, it's easier than having to type it twice)

However, when I do:

password.PasswordChar = null;

It says

Cannot convert null to 'char' because it is a non-nullable value type

Setting it to '' says it's an empty char, and ' ' just makes it a space. What do I do?



Solution 1:[1]

You should be able to do this:

password.PasswordChar = '\0';

Solution 2:[2]

password.PasswordChar = '\u0000';

'\u0000' means null character in Unicode and it does the same thing as '\0'

Beware that single quote is using to represent char.

Solution 3:[3]

enter image description here

vb.net

 txt_password.PasswordChar = String.Empty

C#

  txt_password.PasswordChar = string.Empty;

Checkbox working:

  Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
    If CheckBox1.Checked = True Then
        txt_password.PasswordChar = String.Empty

    Else
        txt_password.PasswordChar = "*"

    End If
End Sub

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mike Perrenoud
Solution 2 V-SHY
Solution 3 lava