Label.Text property
-
I discovered an interesting occurance today. The below code creates a compile time error as expected...
int i = 5; label1.Text = i;
But this code works fine...int i = 5; label1.Text = "Test " + i;
I had a look on Lutz Roeder's Reflector but couldn't find an obvious reason why this works. Could someone enlighten me? Mark. -
I discovered an interesting occurance today. The below code creates a compile time error as expected...
int i = 5; label1.Text = i;
But this code works fine...int i = 5; label1.Text = "Test " + i;
I had a look on Lutz Roeder's Reflector but couldn't find an obvious reason why this works. Could someone enlighten me? Mark. -
I discovered an interesting occurance today. The below code creates a compile time error as expected...
int i = 5; label1.Text = i;
But this code works fine...int i = 5; label1.Text = "Test " + i;
I had a look on Lutz Roeder's Reflector but couldn't find an obvious reason why this works. Could someone enlighten me? Mark.Hi, in
string + something
if something is not a string, the compiler will replace it bysomething.ToString()
automatically. :)Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
-
I discovered an interesting occurance today. The below code creates a compile time error as expected...
int i = 5; label1.Text = i;
But this code works fine...int i = 5; label1.Text = "Test " + i;
I had a look on Lutz Roeder's Reflector but couldn't find an obvious reason why this works. Could someone enlighten me? Mark.Hi MarkBrock Anything appended to a string is understood as string only by the compiler.
--Here 2 See Sharp-- I have not failed. I've just found 10,000 ways that won't work. :)
-
I discovered an interesting occurance today. The below code creates a compile time error as expected...
int i = 5; label1.Text = i;
But this code works fine...int i = 5; label1.Text = "Test " + i;
I had a look on Lutz Roeder's Reflector but couldn't find an obvious reason why this works. Could someone enlighten me? Mark.Interesting... I had initially thought it may have been something a little more synister deep under the covers of C#. It's interesting that the C# developers decided to add functionality for converting non-string types if they are appended, but not for non-string types on their own. Thanks for clearing that up guys. Mark.