What is the difference between char and Char?

Possible Duplicate:
What is the difference between String and string

When I run:

char c1 = 'a';
Console.WriteLine(c1);

and when I run:

Char c2 = 'a';
Console.WriteLine(c2);

I get exactly the same result, a .

I wanted to know what is the difference between the two forms, and why are there two forms?


The result is exactly the same. Both represent the same type, so the resulting executables are completely identical.

The char keyword is an alias in the C# language for the type System.Char in the framework.

You can always use the char keyword. To use Char you need a using System; at the top of the file to include the System namespace (or use System.Char to specify the namespace).


In most situations you can use either a keyword or the framework type, but not everywhere. For example as backing type in an enum, you can only use the keyword:

enum Test : int { } // works

enum Test : Int32 {} // doesn't work

(I use int in the example, as You can't use a char as backing type for an enum.)


Related: Difference between byte vs Byte data types in C#


据我所知,C# char类型关键字只是System.Char的别名,所以它们引用相同的类型。


关键字char是C#中System.Char类型的别名。

链接地址: http://www.djcxy.com/p/3596.html

上一篇: 字符串或字符串

下一篇: char和char有什么区别?