Difference between string and String in C #? [duplicate]

-2

Example (pay attention to the upper case and lower case):

    string s = "Hola mundo!";
    String S = "Hola mundo!";

What is the correct use of each line? What are the differences?

Basically I would like to know if there are differences in implementation and in which case it would be worthwhile to use one.

    
asked by Juan Carlos Sánchez 23.04.2017 в 06:25
source

1 answer

4

string is an "alias" in C # for System.String. Technically there is no difference. It is similar to using only int instead of System.Int32. However, it is recommended to use string every time an object is referenced.

Example:

string lugar = "mundo";

It is also recommended to use String if you need to refer specifically to the class.

Example:

string saludo = String.Format("Hola {0}!", lugar);

Generally, this style is what Microsoft uses in its examples. It seems that the question is similar to others, so I tried to elaborate a little more on what cases it would be worth using one implementation on the other.

    
answered by 23.04.2017 / 06:27
source