0

Look at the following code. Are they the same? Is there any difference? If yes what?

    string f = textBox5.Text;
    if (string.IsNullOrEmpty(f))
    {
        MessageBox.Show("string");
    }
    if (String.IsNullOrEmpty(f))
    {
        MessageBox.Show("String");
    }

Edit: Is a null or empty string test exactly the same as null or empty String test?

Flood Gravemind
  • 3,773
  • 12
  • 47
  • 79
  • 4
    Why are people voting to reopen this? The duplicate answers the question exactly, or *all* uses of `string` and `String`, *which includes this type of usage*. – Servy Oct 24 '13 at 16:53
  • As per this [_this existing question_](http://stackoverflow.com/questions/7074/whats-the-difference-between-string-and-string) `string` is merely an *alias* for `System.String` as is true for all of the other primitive types. Given this, both statements will call the exact same method so no, there is no difference. – User 12345678 Oct 24 '13 at 16:53
  • @FloodGravemind I *did* mark it as a duplicate. See below, "marked as duplicate by Servy [...]". I do have a problem with people inappropriately reopening a question that is correctly closed. Why shouldn't I be? Why should I ignore something like that? – Servy Oct 24 '13 at 16:58

3 Answers3

2

string is just an alias for System.String, just like object is an alias for System.Object, so in short, they refer to exactly the same thing.

Will Faithfull
  • 1,868
  • 13
  • 20
2

Yes they are the same. string is just an alias to System.String.

Reda
  • 2,289
  • 17
  • 19
2

As ByteBlast said - they are the same thing but string is a keyword (and alias) for String (which is a class). but remember, if you are porting over apps to WinRT, then String does not work - only string.

Ahmed ilyas
  • 5,722
  • 8
  • 44
  • 72