September 29, 2016-language basics: Console input and output, data type, data conversion, operators

Source: Internet
Author: User
Tags arithmetic arithmetic operators logical operators

I. INPUT and OUTPUT

Ii. Types of data

  1. Value types

  2. Reference types

Third, data conversion

Iv. operators

1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Other operators
5. Conditional operators

I. INPUT and OUTPUT

Output     Console.Write ("");     Console.WriteLine ("");
Output

     input     console.read ();     Console.ReadLine ();     Console.readkey ();      Console.ReadLine ();      // until the Enter command is accepted, all input contents are fetched and assigned to the left variable      // the Console.ReadLine () method gets the string type
input

Ii. Types of data

1. Value types

            // integer type  int   ± 2.1 billion             // integer type  long            int1;             // declare more than one            at a time int a,b,c=4, D;    
integer Type
            // single-precision floating  -point fractional float  (  value f  )            float3.14f;             // double-precision floating-point decimal double  (  value  )double do            3.14;             // double-precision floating point decimal decimal  (  value m  )            decimal3.14m;
floating point Decimals
            // boolean bool (true,false)            BOOL true ;             // b equals 1==3 results.            BOOL 1 3;
Boolean type

2. Reference types

            // String Type            string " 11231564 " ;             " 123 " ;             // -----------------------------            string St;             "";
String Type

* constant

            // Constants--add--const            before variable names // constants are not assignable, only desirable values            Const int 5;
Constants

Third, data conversion

            // Cast---Example: decimal to Integer, discard all            after decimal point Double 3.14 ;             int b = (int) A;
(int) variable conversion
            // convert.to*--to various types            string " 123 " ;             int j = Convert.ToInt32 (s);
convert.to* (variable) conversion
            // Parse (variable)--go to various types            string " 123 " ;             int int. Parse (s);
Parse (variable) conversion

Iv. operators

1. Arithmetic operators

            //+ + In normal use, is on its own basis on the +1 operation//in the assignment operation,//the first + + needs to perform a +1 operation before assigning a value//Post + + needs to perform the assignment first, then the +1 operation//--likewise            intA =5; intb = a++;//int b = a;a+=1;            intc = ++a;//A+=1;int C = A;a++;//a+=1 a=a+1a--;//a-=1 A=a-1++a;//a+=1 a=a+1--a;//a-=1 A=a-1
+ +--operator
            // *  /  % operator             // determine if A is a multiple of B ()            int4;             Double 5.5 ;             * b);    
*/% operator
            // +  -  operator            int4;             Double 5.5 ;             + b);                     // Note: The + sign is spliced when it encounters a string type
+-Operator

2. Relational operators

            // > < >= <= = =             =! // int a = 4;             // double b = 5.5;             // Console.WriteLine (a > B);    
> < >= <= = = = Operator

3. Logical operators

&&---with two conditions at the same time to true, otherwise false

|| ---or two conditions one satisfies to true, neither satisfies is false

! ---non (highest priority) The original true becomes False,false true

4. Other operators

            // Assignment Operators             // =  + = =  *=  /=   %=            int i =1;            I+ =2;
Assignment Operators

5. Conditional operators

            // ?  :            int 5 ;             int b = a++;             string " is a " " It 's weird . " ;            Console.WriteLine (c);
? : operator

* Little Practice

1.

Q: What time is it? We only answer a few points
If you need to add an AM in the morning
In the afternoon, you need to add a PM, on the original value-12 timekeeping

Console.Write ("Q What time is it? \ n Please enter"); intTime =int.            Parse (Console.ReadLine ()); stringc = time > A?"PM"+ (Time- A) :"AM"+Time ; Console.WriteLine ("is now"+c); Console.Write ("enter any key to end"); Console.readkey ();
Answer:

2.

Please enter an integer within 100 to determine if it is related to 7
Multiples of 1.7
2. Single digit is 7
3.10-digit is 7

Console.Write ("Please enter an integer within 100:"); intA =int.            Parse (Console.ReadLine ()); Console.WriteLine ("is it a multiple of 7? "+ (a%7==0)); Console.WriteLine ("is the single digit 7? "+ (a%Ten==7)); Console.WriteLine ("is the 10-digit number 7? "+ (A/Ten==7)); Console.Write ("enter any key to end"); Console.readkey ();
Answer:

3.

Can you run over the leopard?

Console.Write ("can you run over the leopard? "); stringstr =Console.ReadLine (); strings = str = ="can be"?"You're more animal than a beast .":"you don't even have an animal .";            Console.WriteLine (s); Console.Write ("enter any key to end"); Console.readkey ();
Answer:

September 29, 2016-language basics: Console input and output, data type, data conversion, operators

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.