C # programming structure basis (say the second teacher who Programming Division)

  • Variable (variable) and data type (the DataType)

Variable is a memory address alias (using a variable name to find the corresponding virtual memory), not directly encoded memory address, because different computer hardware or computer operating system from accessing the data mode.

Declare variables is the creation of a virtual memory; variable assignment is the variable corresponding memory written assignments between data variable is the assignment data, and then stored.

The container seen as variable, int value = 100; int type variable called value; live variables in memory, the memory address of the memory = + memory cells; assembly language, can be used to find the memory address of the memory means of accessing data, limited by hardware and operating systems. Is not particularly specified memory address, the name to use of accessing data, namely the variable name. Assignment: the use of a variable name to find the corresponding memory area, the data is converted to binary, to save memory space.

GetType (variable): derived type variables; typeof (int) for comparing the variable type, whether int

the sizeof (variable): derived variables occupy memory unit (4-byte, 32-bit)

int 32 bit double 64 bit 100.6d a float 32 bit 100,5f Long 64 bit: 100L

C # employed in lowercase int double float long need to be converted to the basic data types supported by the CLR , uppercase system.int32 = int system.int64 = long system.Single = float system.Double = double ( similar to the base class)

String and   String is not case sensitive , can be compared using the typeof, will be compiled into system.string 

Var keyword, implicitly typed variables used to streamline the code. The use of the type of value to infer their own type.

Data type conversion : direct conversion into small, implicit conversion becomes small Dayong Method: (int cast, int.parse, convert.toint32, tostring () string + "", generally not prompt implicit conversion)

Categorical variables: Value Type + reference type , the former survive in the thread's stack, which survive in the heap

Operators and expressions , integer / integer = supplier, using modulo%, modulus. ++ - increment, decrement operators.

IF and Switch 

Logic Expression is true or False, the logical expression in combination with non && and ||!

Note: => as lambda expressions. Different from> =

switch attention to grammar switch (variable) case value: execute a statement; break; finally default:

 static  void the Main ( String [] args) 
        { 
            Console.WriteLine ( " Please enter the first digit " );
             int A = int .Parse (Console.ReadLine ()); 
            Console.WriteLine ( " Please enter the second digit " );
             int B = int .Parse (Console.ReadLine ()); 
            Console.WriteLine ( " Please enter the operator " );
             String S = Console.ReadLine ();
             Switch (S) 
            { 
                Case  " +" :
                    Console.WriteLine(a+b);
                    break;  
                case "-":
                    Console.WriteLine(a-b);
                    break;
                case "*":
                    Console.WriteLine(a*b);
                    break;
                default:
                    Console.WriteLine(a / b);
                    break;
            }
            Console.ReadKey();
        }
    }

loop statement:

for circulation, we know the number of cycles, and each time step size.

while loop, to know the conditions of the cycle.

Do-While loop, to know the conditions of the cycle, after the first circulation loop body is executed determination conditions.

console tips:
know the key, use the console readkey method. The return value control keyinfo

 Call methods, there are static and non-static points, can directly use the static method name to call, or by class name + method name. Non-static methods, usually invoked by instantiating objects.

Stack overflow, the stack area of ​​memory called threads, his limited storage space. Avoid overflow, in recurrences that is smaller in scale convergence.

 static  Long the Factorial ( int n-) 
        { 
            IF (n-== . 1 )
                 return  . 1 ;
             Long RET; 
            RET = the Factorial (n-- . 1 ) n-*; // called again, smaller scale 
            return RET; 
        }

Note that the computer can not accurately compare two values, using the general method of ABS Math class, calculating an error between the two values, and error and the like 1e-10 were compared.

Guess you like

Origin www.cnblogs.com/LljCoder/p/11029507.html