Is this valid C# syntax?
tboxUserName.Text = "This is silly";
if (tboxUserName.Text == NULL)
{
tboxUserName.Text = tboxUserName.Text + "Very Very silly!";
}
Can you add to the contents of a field in the above way?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Roy SPosted Jan 30, 2013, 1:49 PM
richard smithPosted Jan 30, 2013, 2:14 PM
Anywho, thank you for confirming that is valid C# syntax.
VulpesPosted Jan 30, 2013, 2:03 PM
richard smithPosted Jan 30, 2013, 1:57 PM
So for example sake...
tboxUserName.Text = "This is silly";
tboxUserName.Text = tboxUserName.Text + "Very Very silly!";
My first value is getting overwritten by my 2nd value?
VulpesPosted Jan 30, 2013, 1:54 PM
1. You wouldn't test a string for nullness immediately after setting it to a string literal!
2. The Text property of controls is never 'naturally' null in any case - it's default value is an empty string.
3. If you concatenate a null string with a non-null string, the former is treated as if it were empty and so, if you know it's null, concatenation is a pointless operation.
However, there's nothing wrong with setting the Text property of a control to its existing value concatenated with one or more non-null strings. This is quite a common operation.
richard smithPosted Jan 30, 2013, 1:51 PM