c#中char
C#char关键字 (C# char keyword)
In C#, char is a keyword which is used to declare a variable that can store a character value (Unicode value) value between the range of +U0000 to U+FFFF. char keyword is an alias of System.Char.
在C#中, char是关键字,用于声明一个变量,该变量可以存储+ U0000到U + FFFF范围内的字符值(Unicode值)。 char关键字是System.Char的别名。
It occupies 2 bytes (16 bits) in the memory.
它在内存中占用2个字节(16位)。
Syntax:
句法:
char variable_name = value;
It can store the character between the range of Unicode +U0000 to +UFFFF.
它可以存储Unicode + U0000到+ UFFFF范围内的字符。
C#代码演示char关键字的示例 (C# code to demonstrate example of char keyword)
Here, we are declaring a char variable chr, initializing it with the value 'X' and printing its value, type and size of a char type variable.
在这里,我们声明一个char变量chr ,使用值'X'对其进行初始化,并打印其值, char类型变量的类型和大小。
using System;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
//char variable declaration
char chr = 'X';
//printing value
Console.WriteLine("chr: " + chr);
//printing type of variable
Console.WriteLine("Type of chr: " + chr.GetType());
//printing size of a bool
Console.WriteLine("Size of a char variable: " + sizeof(char));
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
chr: X
Type of chr: System.Char
Size of a char variable: 2
翻译自: https://www.includehelp.com/dot-net/char-keyword-in-c-sharp.aspx
c#中char