Answer: String.Empty is a readonly field, while "" is a constant
Consider this code snippet.
private void button1_Click(object sender, EventArgs e)
{
string s = textBox1.Text;
switch (s)
{
case String.Empty:
MessageBox.Show("blank");
break;
}
}
//Compiler will generate an error
//A constant value is expected
//So, if we use "" in place of String.Empty, no error will be generated.
Asked In: Many Interviews |
Alert Moderator