C # Learning Diary character Types---data types

Source: Internet
Author: User
Tags control characters
Character type of numeric type:

Computer processing of information in addition to numbers, mainly characters, characters include numeric characters, English character, expression symbols, and so on; C # provides character types in accordance with internationally accepted standards, using the Unicode character set, a standard Unicode character length of 16 bits, It can be used to represent many languages in the world. The assignment of a character variable in C # is similar to C + +:

Char ch = ' H '; Sometimes when we enter the names of people also use the char type, such as the previous diary 03 I used char sex, to enter my gender, so that a Chinese character is also a char?? Yes, a Chinese character accounts for 2 bytes, 1 bytes is 8 bits, and a Chinese character is just 16 bits, so it counts as a character; so char sex = ' man ' is a legitimate compilation.

In addition, we can assign a value to a character variable directly by means of hexadecimal escape or Unicode notation, for example:

Using System;  Using System.Collections.Generic;  Using System.Linq;  Using System.Text;    Namespace Example  {      class program      {          static void Main (string[] args)          {              char c = ' \x0032 ';  \x is a 16 binary escape symbol at this point, 32 is the 16-              char d = ' \u0032 ';  The 32 under \u represents an encoding for Unicode              Console.WriteLine ("c = {0}\td = {1}", C,d);}}  

Run it:

So the above assignment is the same as char C = ' 2 ' char d = ' 2 ';

In the spirit of a courageous exploration of the heart, I have to explore the code above. \U0032 represents a character encoded as 0032 in Unicode, \x0032 represents 0032 of the 16 binary, and the Unicode encoding is the value of 16 binary, and I try to change the code to read as follows:

char c = ' \x0033 ';

Char d = ' \u0034 ';

I guess the result will be c=3 d=4; The running result is exactly that, the above is established.

In the spirit of cranky, I also think of learning C when using the ASCII code value, will asclii code value and Unicode code value is the same? I found the C language textbook, the query to 2 ASCII decimal code value is 50 is not 32, because the above conjecture set 32 is 16 in the System 32 I convert it into 10 what is it??? (This is the test to me, when the teacher said in the conversion, I ... Alas! Do not say, "when the book to the time square hate Ah!" "), but we can use C # to write a binary conversion program to calculate the following code:

Using System;  Using System.Collections.Generic;  Using System.Linq;  Using System.Text;    Namespace Example  {      class program      {          static void Main (string[] args)          {                            Console.Write (" Please enter a hexadecimal number: ");                string x = Console.ReadLine ();              Console.WriteLine ("Hexadecimal {0} decimal number is represented as: {1}", X, Convert.ToInt32 (x, 16)); Convert.ToInt32 (x, 16) Converts the 16 binary X to 10, the            int type is decimal, and              the Console.WriteLine ("Hexadecimal number of decimal 50 is represented as: {0}", Convert.ToString (50,16));//convert.tonstring (50,16) binary conversion  or int a =;              A.tostring ("X");}}}  

The result is this:

Sure enough, the ASCII code value in hexadecimal is equal to the Unicode character code value, and the data can be read as follows:

ASCLL codes are all in English and some special symbols (tabs, etc.),
There are not only English and special symbols in Unicode, but also Japanese, Korean, Chinese ...
Unicode is now generally used (this is why in Journal 04 C # supports naming variables in Chinese)


As in C/C + +, there is still an escape character that is used to refer to special control characters in the program ...

May not know \a give an example Console.WriteLine ("\a\a"); will make 2 "beep" sound, you try ...


The description of the character type is here, and finally in order to eliminate all the questions, I want to figure out how to write the conversion in C/s + +, it seems to have to consult the teacher.

(if there is any wrong place to hope that the great God guidance, will be grateful!!!!! )

The above is the C # Learning Diary---Data type of the content of the character type, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.