String vs string [duplicate]

我与影子孤独终老i 提交于 2019-11-29 09:05:10

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

No difference. System.String is strictly identical to string. Common C# coding guidelines indicates that you should use the keyword string.

They are aliases and are interchangeable. However, stylistically, for declarations, I use the lowercased string, and for the static methods, I use String.

string foo = "bar";

if( foo != String.Empty )
{
   Console.WriteLine(String.Format("foo.Length = {0}", foo.Length));
}

One is System.String the .Net Type and one is specific to C# which turns out to be an alias back to System.String.

http://msdn.microsoft.com/en-us/library/362314fe(VS.71).aspx

There is not a difference. string is an alias that the compiler converts to System.String.

In fact, it's even aliased in MSIL:

.method private hidebysig static void  Main(string[] args) cil managed

There is no difference between them. string is just an alias for System.String. When compiled they both are compiled to System.String object.

The lower case version is just an alias to the actual class String. There is no real difference as far as IL generated.

There is no difference. string is a C# language keyword which refers to the class System.String, just like int is a keyword which refers to System.Int32.

In the future, try compiling an app that uses both and then use Reflector (change the language to IL) to view the compiled output. You'll see there's no difference.

There is no difference because string is converted to System.String by the compiler. Same with all of the common types (int goes to System.Int32, etc). We use the simple name so they stand out.

Considering that an “int” is different in some languages depending on 16bit/32bit system, a "string" could in the future evolve to not be the same as System.String.

But for now it is.

just a bit note: string/String is not the only couple of aliases: eg. Integer,Int32, int are all aliases.

@mliesen: it doesn't happend in C#, it's not like C. this because from C# you don't create executable but a per-compiled code, as java.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!