Well i do believe that string , object are reference types :) so there default values when not initialized should be NULL right ??
Humm now the problem ..
I have a textbox where when applied the text property on it te output should be in STRING FORMAT am i right here ??
Well now i applied like this
int a = Convert.toInt32(TextBox1.text);
messagebox.show(a);
But i am getting exception : Input string was not in a correct format.
I given no input to textbox i.e i hoped it will take NULL by default but its not happening .. instead its taking this "" .. Y Y Y .
I hope i am clear with my doubt ??
Ty for help
Have a nice day

VulpesPosted Oct 1, 2013, 6:26 AM
Somewhere within that class there will be a backing field (let's call it _text) which the property gets and sets.
Although the default value of that field will be null, it is being set to "" instead either within its declaration:
private string _text = "";
or within the TextBox constructor.
The default value of the comboBox.Text property is also an empty string.
Incidentally, you can always check what the default values are by executing a lline like this when the textbox or combobox input area is empty:
MessageBox.Show((comboBox.Text == "").ToString());
Even though the default values are an empty string, there's nothing to stop you explicitly setting them to null if you want to for some reason. This compiles and runs fine:
textBox1.Text = null;
However, internally, I suspect that it will be set back to "" if you do this.
SUNIL GUTTAPosted Oct 1, 2013, 5:49 AM
Is my assumption wrong ? i.e text.text which gives us empty string i.e "" by default ? but why is it so ?? being a reference type why it is giving me "" not NULL ? Y Y
But in case of comboBox i.e it does give Null when nothing entered which is OBJECT (return type) which in turn a reference type its sucessfully initialised to ZERO . .
?? ?? /?
Joxin StanlyPosted Oct 1, 2013, 5:41 AM
it is because the default of TextBox.Text is an empty string ("") not NULL.
VulpesPosted Oct 1, 2013, 5:40 AM
However, you can deal with this possibility with the following code:
int a;
int.TryParse(TextBox1.Text, out a);
If the TextBox is empty or contains something which isn't an integer, a will be now be set to zero.
SUNIL GUTTAPosted Oct 1, 2013, 5:36 AM
I just want to know what happens internally when we give nothing to textbox i.e its taking "" instead of NULL yy .. a big yyy
Joxin StanlyPosted Oct 1, 2013, 5:31 AM
as per your code int a = Convert.toInt32(TextBox1.text);
Textbox1 should have a value that can be converted to an integer.
and then you have to try below-:
Messagebox.show(a.ToString());