3. Variable Constants
Preface:
In fact, I was reviewing this item when I was writing it, because it was a year ago. Today I have read several chapters and paste them here. I am also asking for advice, because there are many types of variables that I can't really remember. I only need to remember or check the information when I use them.
Why? For short-term projects, access, sqlserver, and Oracle are used. I started to write down my documents and put them in front of my office seat ....
Variable (INT Int = 0)
1. Value Type
(1) Integer
Type |
Description (Binary) |
Range |
Sbyte |
8-Bit Signed |
-128-127 |
Byte |
8-bit unsigned integer |
0-255 |
Short |
16-Bit Signed |
-32768--32767 |
Ushort |
16-bit unsigned |
0-65535 |
Int |
32-Bit Signed |
-2147483648--2147483647 |
Uint |
32 is unsigned |
0-4294967295 |
Long |
64-Bit Signed |
-9223372042554775808--.5807 |
Ulong |
64-bit unsigned |
0-18446744073709551615 |
(2) floating point type
Type |
Description |
Range |
Float |
7-digit |
10 to the power of 45-38 |
Double |
15-16 digits |
10 to the power of 324-308 |
(3) Boolean Type
Bool x = true or false
(4) Special: Enumeration type
Enum enumeration name
{List1 = 1, list2 = 2 ,...} Enumeration can be integer, floating point, or Boolean
Small knowledge accumulation: (int) Datetime. Now(). Dayofweek;Return to the day of the week (the minor knowledge is not necessarily related to the subject, but I copied it when I saw the case in the book, the same below)
2. Reference Type (defined in stack, memory space, and value type in heap memory space)
Define a class value and assign the value: Class int {int A = 0 ;}; class usingint {Int. A = 10 ;}
Constant-Const: const in Tint = 0; tint is fixed
Iv. Expressions and operators
1. Arithmetic Operators
+,-, *,/, % Perform the remainder operation;
2. Value assignment operator
Such as =, + =,-=, * =, & =, >>=, and so on. Generally, this parameter indicates the combination of operator numbers. It is used for value assignment and value assignment (Operator name + value assignment ), I + = 2 is equivalent to I = I + 2;
3. Relational operators (comparison)
= Equal to,>, <,! =, >=, <=, Compares and returns a boolean result.
4. logical operators
(1) By bit (compare the values on the binary digits, 0 or 0 & 1 = 0 returns the decimal number of 0, 0 | 1 = 1, returns the decimal number corresponding to 1;
(2) In a Boolean budget (condition conditions): &, | or, ^, or;
5. Shift Operator-used to move the binary position corresponding to the computer variable:
> Right shift, <left shift: string a = 5; A> 1, A <-binary 010, shifted to 01, corresponding to decimal 3
I understand digital movement by drawing pictures, but I can't do it if I have never been so advanced.
6. Other operators
Name |
Description |
Example |
Is |
Used to check whether the specified type is used |
Bool B = 0 is int; B returns true |
? Conditional Operators |
Variable? Established: not established |
String YN = (bool) B ?" Yes ":" No "; B is set to B = yes; B is not set to no |
New |
Create a new type instance |
String [] S = new string [5]; s [0] = 1, s [1] = 2... |
Typeof |
Get the namespace to which the object belongs. Type |
Type T = typeof (INT); console. Write (t) returns sysytem. int32 |
The priority of operator numbers is high-low: attribute typeof, etc. --- one dollar (! ++, -- Increase and decrease) -- multiplication, division, subtraction, -- shift> -- Comparison <>=-- bit and -- bit or -- logic and or -- condition? -- Value assignment: + = and so on
5. characters and strings
(Char, String, char set to synthesize string)
1. Character char class: represents a Unicode Character
1.1char. method (parameters, objects, etc.) p64, commonly used:
Console. writeline ("judge whether it is a letter: {0}", Char. isletter ());
Console. writeline ("judge whether it is a number: {0}", Char. isdigit (B ));
Console. writeline ("judge whether it is a number or a letter: {0}", Char. isletterordigit (c ));
Console. writeline ("lowercase: {0}", Char. islower ());
Console. writeline ("judge whether punctuation: {0}", Char. ispunctuation (d ));
Console. writeline ("determining whether it is a separator: {0}", Char. isseparator (e ));
Console. writeline ("judge whether it is a space: {0}", Char. iswhitespace (f ));
In addition, Char. tostring (a); Char. toupper (A) and so on are used to convert the data to the corresponding type.
1.2char Escape Character "\" backslash: \ n-press enter to wrap; \ t to jump to the next character, \ v vertical line feed, \ B Return, \ r press enter, \ f form feed,
\ Punctuation marks-punctuation marks (preventing program obfuscation)
2.StringStringClass(Key, char set)
(1) The sringbuilder class is recommended for convenience and practicability.
Using system. text;
Stringbuilder strb = new stringbuilder ("string", 100); // (string, initial size)
Strb. append ("the characters appended to the original string ");
Strb. appendformat ("{0: c}", 1000) // specify the append format as {0} type C currency with the content as "1000"
Strb. insert (0, "name") // (the number of places to be inserted starting from scratch. The content to be inserted)
Strb. Remove (15, strb. Length-15); // (the starting position of the removal, the number of digits of the removal)
Strb. Replace ("the characters to be replaced", "the characters to be replaced ");
(2)StringUsage
*Comparison: String. Compare (a, B), A. compareto (B) // AB-A> BResult1, Equals to the result0, Less than the result-1
String. Equal (a, B), A. Equal (B) is equal to true, otherwise false.(Strings are generally larger than English letters and later than English letters)
*Format String:String. Format ("{0:Format specification}, {1 },...,",Parameters1, Parameter2 ...)
This is also quite common. Generally, this type of data is easy to be formatted from the database, and the format can be used to solve the DB exception that is common to new users.
Format specification:
D-yyyy-mm-dd; D-Year-month-day; t-hour: minute: Second; F-Year-month-day hour-minute-second;
The time format of G and G sorting is year, month, and day (second); m month and day; y year and month; C-currency ¥
*Split string: The split result is the array string [] Ss = A. Split ("split character or symbol 1", "split character or symbol 2 ",....,), Then, use foreach (string STR in SS) {console. writeline (STR);} to list all the strings formed by segmentation.
*Insert and fill:Str1.insert (start position, content to be inserted); fill Str. padleft/right (total length of the string after addition, added content)
*Delete string:Str1.remove
*Copy characters: Str2 = string. Copy (str1); str1.copyto (starting position of str1, starting position of str2, starting position of str2, number of digits that str1 needs to copy)
* Replacement character: str1.replace (content to be replaced, content to be replaced );
In terms of project experience, split is a good thing. Many interfaces developed on the big platform return strings or decrypted MD5 strings, which are generally divided by special symbols such as "|" and "¥ %, in this case, split the data into arrays to extract the corresponding information.
Non-computer-specialized codenon C # Study Notes 3. Variable expression string