-1

What is the difference between

public static void Main (String[] args)

and

public static void Main (string[] args)

in C#? I am using SharpDevelop 4.3.1 as the development environment.

If I am using string it is highlighted in red but when I am using String it is highlighted in black. Checking online I found out that both String and string are the same, if so why are they highlighted differently?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rahul.In
  • 61
  • 9
  • Nope, `string` is a synonymous for `String`. – Tony Jan 30 '14 at 06:22
  • 1
    The same as between `String` and `string` = none. They are highlighted differently because `String` is name of class and `string` is a keyword aliasing to that class. – MarcinJuraszek Jan 30 '14 at 06:23

1 Answers1

0

String is a class name so you can create n number of object to implement its methods. where as string is reserved word This means that 'string' cannot be used as a variable name by itself.

If for some reason you wanted a variable called string, you'd see only the first of these compiles:

StringBuilder String = new StringBuilder();  // compiles
StringBuilder string = new StringBuilder();  // doesn't compile 

If you really want a variable name called 'string' you can use @ as a prefix :

StringBuilder @string = new StringBuilder();
vino20
  • 429
  • 4
  • 13