The following (C#) code snippet sets the text property of a label to null,
then tests it for null, only to find out that is isn't. Can anyone explain
why?
Label1.Text = null;
if (Label1.Text == null) {
Label2.Text = "Is null";
} else {
Label2.Text = "Is not null";
} 4 2001
The short answer is - if you check in your debugger - when you set it to
null it is actually set to "".
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:E3******** *************** ***********@mic rosoft.com... The following (C#) code snippet sets the text property of a label to null, then tests it for null, only to find out that is isn't. Can anyone explain why?
Label1.Text = null; if (Label1.Text == null) { Label2.Text = "Is null"; } else { Label2.Text = "Is not null"; }
Well I noticed that it is set to "". However, it works fine if you use a
string variable. I realize that there is a difference between a string
property, such as Text and a string variable, it just seems to me they should
behave more similarly.
--Mike
"Jediah L." wrote: The short answer is - if you check in your debugger - when you set it to null it is actually set to "".
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message news:E3******** *************** ***********@mic rosoft.com... The following (C#) code snippet sets the text property of a label to null, then tests it for null, only to find out that is isn't. Can anyone explain why?
Label1.Text = null; if (Label1.Text == null) { Label2.Text = "Is null"; } else { Label2.Text = "Is not null"; }
some properties have code under them... apparently, in this case, if you
attempt to set the Text property to a null, the code forces the value to
String.Empty.
It makes sense. The Text property of a control can't really be null. Null
is not a value. It means that "no value is known". Since the control has
to render the value, it makes sense that it would require you to provide
one.
Be happy you didn't get a runtime error.
--- Nick
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message
news:F1******** *************** ***********@mic rosoft.com... Well I noticed that it is set to "". However, it works fine if you use a string variable. I realize that there is a difference between a string property, such as Text and a string variable, it just seems to me they
should behave more similarly. --Mike
"Jediah L." wrote:
The short answer is - if you check in your debugger - when you set it to null it is actually set to "".
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message news:E3******** *************** ***********@mic rosoft.com... The following (C#) code snippet sets the text property of a label to
null, then tests it for null, only to find out that is isn't. Can anyone explain why?
Label1.Text = null; if (Label1.Text == null) { Label2.Text = "Is null"; } else { Label2.Text = "Is not null"; }
Yup, I guess there must be code back there that makes sure Text is never
null. Thanks for your comments.
"Nick Malik" <ni*******@hotm ail.nospam.com> wrote in message
news:g0AYc.3331 88$a24.112462@a ttbi_s03... some properties have code under them... apparently, in this case, if you attempt to set the Text property to a null, the code forces the value to String.Empty.
It makes sense. The Text property of a control can't really be null.
Null is not a value. It means that "no value is known". Since the control has to render the value, it makes sense that it would require you to provide one.
Be happy you didn't get a runtime error.
--- Nick
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message news:F1******** *************** ***********@mic rosoft.com... Well I noticed that it is set to "". However, it works fine if you use
a string variable. I realize that there is a difference between a string property, such as Text and a string variable, it just seems to me they should behave more similarly. --Mike
"Jediah L." wrote:
The short answer is - if you check in your debugger - when you set it
to null it is actually set to "".
"Mike" <Mi**@discussio ns.microsoft.co m> wrote in message news:E3******** *************** ***********@mic rosoft.com... > The following (C#) code snippet sets the text property of a label to null, > then tests it for null, only to find out that is isn't. Can anyone > explain > why? > > Label1.Text = null; > if (Label1.Text == null) { > Label2.Text = "Is null"; > } else { > Label2.Text = "Is not null"; > } >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: |
last post by:
Hi,
I am setting the NumericUpDown .Value property and the ValueChanged event
is NOT being fired. Does this ONLY get fired when I change it on the UI and
not programatically?
Thanks
|
by: Michael Bierman |
last post by:
Please forgive the simplicy of this question. I have the following code
which attempts to determine the color of some text and set other text
to match that color. It works fine in Firefox, but does nothing in IE.
I'd be greatful for any assistance. Also, if I will have problems the
code on Opera or Safari, I'd appreciate any pointers--I don't have a
Mac to test Safari.
THanks very much,
Michael
|
by: Praveen |
last post by:
Hello.
I am writing some code that accepts a DFS Link and Username and grants that
User permissions to the physical directory that the DFS Link corresponds to.
I am using the System.Management namespace and WMI queries.
When I run the code below and check the Security tab of the folder , I find
that all entries have been cleared – which is ok and this is expected, main
problem is that the User that I have set up the Trustee and ACE...
|
by: MLH |
last post by:
Combo box LimitToList property setting of No does not
prevent the MS Access error "The text you enter must
match an entry in the list" from popping up. What makes
this bad is that the error is not a capturable error.
My list has 2 fields: and . The
2nd column is the bound column.
Here's the RowSource property setting:
Select , From ;
|
by: MLH |
last post by:
I have an A97 table with a Yes/No field named
TowJob and a form bound to that table. The
TowJob control on the form is bound to the same
field. It is an option group with Yes and No bttns
valued at -1 and 0 respectively.
Unless I specifically set the table field's defaultvalue
to Null, the form comes up with an automatic value
of 0 in the control? The control has NO default
value property setting. Why is that?
| |
by: Dixie |
last post by:
Can I set the Format property in a date/time field in code?
Can I set the Input Mask in a date/time field in code?
Can I set the Format of a Yes/No field to Checkbox in code?
I am working on a remote update of tables and fields and can't find enough
information on these things.
Also, how do you index a field in code?
|
by: Mike |
last post by:
The following (C#) code snippet sets the text property of a label to null,
then tests it for null, only to find out that is isn't. Can anyone explain
why?
Label1.Text = null;
if (Label1.Text == null) {
Label2.Text = "Is null";
} else {
Label2.Text = "Is not null";
}
|
by: laredotornado |
last post by:
Hi,
I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed
using Apache's apxs and the php library was installed to
/usr/local/php. However, when I set my "error_reporting" setting to be
"E_ALL", notices are still not getting reported. The perms on my file
are 664, with owner root and group root. The php.ini file is located
at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem
to be having an effect? ...
|
by: David Veeneman |
last post by:
I'm creating a UserControl that uses a LinkLabel. For reasons that I won't
bore everyone with, I don't want the LinkLable to show the default hand
cursor when the mouse enters the control. Should be a simple setting on the
LinkLabel.Cursor property, right? Not so simple.
I set the property, but still got the default 'hand' cursor. To debug, I
added the following event handler to my LinkLabel control:
private void...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |