C # Learning Diary integer type---data type

Source: Internet
Author: User
In the previous article we initially understand some data types, not comprehensive, in the spirit of earnest and realistic, I again on the data type comb.

Integer type of value type:

Remember before the C language class when the teacher also let us read this form request to write down, at that time also did not take a good look to remember this no use, but when I run the code below to know the teacher's good intentions:

Using System;  Using System.Collections.Generic;  Using System.Linq;  Using System.Text;    Namespace Example  {      class program      {          static void Main (string[] args)          {short              x = 32766;              x + +;              Console.WriteLine (x);              x + +;              Console.WriteLine (x);              Console.readkey ();}}}  

The results are expected:

For Mao is negative???? This time the chapter is now the great place to take the value range 3268 he is beyond the short range of values;

Similar experience has a lot, remember once the teacher asked us to write a program to enter a person's telephone number, and then output, the deskmate said "very simple, rinsed on the written," The Code is as follows:

Using System;  Using System.Collections.Generic;  Using System.Linq;  Using System.Text;    Namespace Example  {      class program      {          static void Main (string[] args)          {              int x;              Console.WriteLine ("Name:");              String name = Console.ReadLine ();              Console.WriteLine ("Phone Number:");              x = Int. Parse (Console.ReadLine ());   Type conversion              Console.WriteLine ("Your name is:" + name + "\ T" + "your phone is: {0}", x);}          }  

The result cannot be run because the valid digits of int are only 11 bits out of range for 10 digits and can be replaced with a long type. Add one point to the input and output: Console.WriteLine ("Your name is:" +name) the middle Plus + denotes the meaning of connecting 2 strings, that is, the meaning of unity, when there is a string type in the expression, such as

int i =9;  String Str = "HC666"  Console.WriteLine (Str+i);

Run the output as:

    HC6669

This is because the compiler automatically converts an int to a string type (implicit conversion) and then joins it when there is a string type and an int type in an expression. Implicit conversions are learned later.

In the spirit of learning, the exploration of the previous diary I have a new discovery: the definition of variable names with Chinese characters is also possible, and not error.

Using System;  Using System.Collections.Generic;  Using System.Linq;  Using System.Text;    Namespace Example  {      class program      {          static void Main (string[] args)          {              string name = "HC666";              int age =16;              Double height =1.70;              Console.WriteLine ("Name: {0}, Age: {1}, Height: {2}", name, age, height);}}}  

In fact, C # is to support multi-language writing, not only Chinese, in Japanese, Korean ... can also, but the proposal is still in English!! Just practise English.


The above is the C # Learning Diary---Data type of integer type content, 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.