Difference between String.Empty and ""

 Posted by Ddd on 2/12/2011 | Category: .NET Framework Interview questions | Views: 4441 | Points: 40
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 

Comments or Responses

Login to post response