C # Getting Started classic Chapter3 variables and expressions

Source: Internet
Author: User

3.1 C # Basic syntax

  Semicolon concluding sentence

Curly brace characters do not need to be accompanied by semicolons

Indent Comment:/*....*/,//,///

Case sensitive

3.2 Basic structure of C # console applications

namespacechapter3{usingSystem;  Public classProgram {Static voidMain (string[] args) {            int[] factor =New int[4]; BOOLIsrightint; inti =0;  Do            {                Try{Console.WriteLine ("Please enter the {0} integers:", i +1); Factor[i]=Convert.ToInt32 (Console.ReadLine ()); Isrightint=true; I++;                Console.WriteLine (); }                Catch(Exception e) {isrightint=false; Console.WriteLine ("the number you entered is in the wrong format, please re-enter it. ");                Console.WriteLine (); }            }  while(!isrightint| | i<4); Console.WriteLine ("the product of {0},{1},{2},{3} is {4}", factor[0], factor[1], factor[2], factor[3], factor[0] * factor[1] * factor[2] * factor[3]);        Console.readkey (); }    }}

Code outline features: #region和 #endregion

3.3 Variables

  1. Simple Type

① integer type: byte sbyte short ushort int unit long ULONG

② floating-point type: Double float decimal

③ text and Boolean type: char bool string

(Escape character)

Console.WriteLine ("{0},{1}", Mystring,myinteger); {0} {1}: Placeholder, equal to the number of variables

Console.readkey (); pauses execution of the code, waiting for the user to press a key to continue.

2. Naming of variables

Basic rule: ① the first character must be a letter, underscore, or @

② subsequent characters can be letters, underscores, or numbers

③ Non-key words

naming convention: ①pascalcase: Advanced variable Big hump named

②camelcase: Simple variable Small hump named

3. Literal value

bool int UINT (u/u) long (l/l) ulong (ul/lu/ul/lu/ul/lu/ul/lu) float (f/f) double (d/d) decimal (m/m) Char string

Escape sequence: Single quotation mark (\ ') double quotation mark (\ ") backslash (\ \) null (\) Warning (\a) backspace (\b) page break (\f) line break (\ n) carriage return (\ r) Horizontal tab (\ t) vertical tab (\v)

A constant string: Use the @ character: where the escape character is not processed and can span rows

4. Declaration and assignment of variables

int age; age=25;

int age=25;

3.4 Expressions

  variable, literal (operand), operator combination-= expression

Operators: One yuan, two yuan, ternary, respectively, processing one, two or three operation number

1. Mathematical operators

Binary: +-*/%

One dollar: +-

String Join operators:

Binary: +

Increment, decrement operator

One dollar: + +-(prefix)

+ +-(suffix) operands are affected by the operator after the completion of the calculation of the expression

2. Assignment operators

Binary: = + = = *=/=%=

3. Precedence of Operators

High Low: + +-(as prefix) +-(unary)

*  /  %

+  -

=  *=  /=  %=  +=   -=

+ +--(used as suffix)

4. Name space (namespace)

Using the Pascalcase naming method

Use a using statement to simplify access to the names it contains

C # Getting Started classic Chapter3 variables and expressions

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.