What is the difference between a string and a string?

What is the difference between these two ads?

string str;
String str;
+3
source share
6 answers

Under normal use stringand stringidentical; string- just an alias for global::System.String. There are some ribs though:

  • you need to using System;use string- you are not using forstring
  • if you define local class String {}, it stringmeans that (this, of course, is a stupid thing). You cannot define a class with a name string(albeit @stringexcellent)
+21
source

There is no difference. string (lowercase) is just an alias for System.String.

+3

- #. String - System.String.NET.

#, MS, string System.String.NET, .

+2

, # . int = System.Int32 short = System.Int16 string = System.String.

+2

String - System.String, .

System.String - Common Type, .NET. "string" - # ( int System.Int32)

+1

They are the same, there is no difference, a string is just an alias for the System.String type, in C # there are other similar cases, such as int and System.Int32, long and System.Int64 (see another related question )

Curious, however, although you can use an alias in your code instead of fully qualified types, you still need to know the base type when you use Convert , because there are no ToInt or ToLong methods, but only ToInt32 and ToInt64 ..

-1
source

Source: https://habr.com/ru/post/1758509/


All Articles