protected void Page_Load(object sender, EventArgs e)
{
bool? isUser = null;
lblStatus.Text = isUser.HasValue.ToString(); //displays false
// an int example: Nullable<int> i = null;
}
protected void btnCheckStatus_Click(object sender, EventArgs e)
{
bool? isUser = false;
lblStatus.Text = isUser.HasValue.ToString(); //displays true
}
Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.
Showing posts with label C# bool. Show all posts
Showing posts with label C# bool. Show all posts
Saturday, June 21, 2008
Using a nullable boolean.
It is possible to assign a nullable boolean in C#. The trick is to use ? in the declaration. Once declared, one can use the HasValue() method. An example follows:
Subscribe to:
Posts (Atom)