Annotations, naming rules, access modifiers, data types, constants, variables
Say a program that won't write a comment Ape's not a good one, we'll start with the comments.
There are three types of annotations in C #:
- First: Single-line comments start with//, followed by comment content
–//Single-line comment
–
- The second type: A multiline comment starts with/*/ends with a comment content
–/* * * Multi-line Comment
–
- The third type: Document comments on the previous line of the method or class///will produce
– ///
–///Document Comments
– ///
–
So .... Is the use of these three kinds of annotations.
say it again. naming rules :
– 1 must begin with a "letter" _ or an @ sign.-- don't start with a number
– 2 can be followed by any "letter", number, underline.
– 3 Camel nomenclature : The first letter in lowercase, the first letter of the remaining words capitalized.
– 4 Pascal named name: Each word is capitalized in the first letter
– If you use abbreviations for English words, capitalize them all!
– Note:
– 1) The variable name you are starting with does not duplicate the keywords in the C # system.
– 2) in C # , casing is sensitive.
– 3) Duplicate definitions are not allowed for the same variable name
Okay, here's the play. The access modifier in C #: [I'll ask you in the interview]
Access modifiers |
Description |
Public |
Public access. Not subject to any restrictions. |
Private |
Private access. This class is restricted to access by members, subclasses, and instances. |
Protected |
Secure access. This class and subclass access is limited, and instances cannot be accessed. |
Internal |
Internal access. Access is limited to this item and cannot be accessed by others. |
protected internal |
Internal protection access. Limited to this item or subclass access, other inaccessible |
The default access modifier in *c# is internal
Again, the data types in C #:
Basic data type Basic data type: value type and reference type.
There will be boxing and unpacking for both basic data types
Boxing: Value types are converted to reference types.
Unboxing: The reference type is converted to a value type.
Packing and unpacking are expressed in code as:
Value type: Data type, struct, enumeration except string.
Reference types: String, class, abstract class, interface, collection, delegate, event.
The difference between a value type and a reference type:
* The value of a value type is stored in the stack of memory .
* The value of a reference type is stored in the heap of memory .
* value type at copy time, pass is this worthy of itself.
* Reference type is a reference to this object when it is copied.
OK The basic data type is finished, and then say a few commonly used data types:
float: Float type
int: integer, signed 32 bits, can only store integers, cannot store decimals
BOOL: Boolean type
BYTE: unsigned, 8-bit
Short: Signed, 16-bit
Long: Signed, 64-bit
String: strings, used to store multiple text, or to store empty, string type values need to be double quotes
Char: A single character, up to, at least one character, cannot be stored empty.
Double: A decimal number that can store both integers and decimals, digits after the decimal point 15~16 bits
* Here I'm going to say it alone. The data type of string, he has immutability , that is, when you re-assign a string, the old value is not destroyed, but re-open a space to store the new value.
When the program finishes, the GC scans the entire memory and destroys it immediately if it finds that the space is not pointing. [Face question]
Since there are data types that involve conversion of data types, there are strong and implicit conversions (automatic type conversions) and display transformations in the conversion:
we ask for an equal sign two times the types of operands that participate in the operation must be identical, and if not, automatic type conversions can occur if the following conditions are met, or they are called Implicit type conversions instead, display type conversions.
Conditions: int and double compatible (both numeric types)
double > int The small one is the implicit type conversion .
Double--->int Big turn-small is the display type conversion
type If the two variables are compatible, you can use an automatic type conversion or coercion type conversion, but if two types of variables are incompatible, such as string with int or string and double , this time we can use a call Convert Conversion factory for the conversion.
Note : Using Convert for type conversion, you also need to meet a condition: Wannna must go on. (That is, you can not change the type of the unthinkable, unrestrained)
All right, there's a whole bunch of side mats that can come in handy:
C # constant in: As the name implies is not to be modified amount.
keyword defining a constant:const
Syntax: Access modifier const data type constant name
Example: Public const int Age
Assignment: Public const int age = 20;
rules for using constants : If you use constants, you should first declare and re-use them.
Variables in C #: As the name implies is the amount that can be changed.
syntax: access modifier data type variable name;
For example: public int age
Assignment: public int age = 20;
rules for using variables : If you use variables, you should declare and re-use them first.
Scope of the variable:
the scope of a variable is the extent to which you can use the variable.
the scope of a variable is usually the end of the parenthesis that declares it, starting at the end of the parenthesis that corresponds to it.
within this range, we can access and use variables. Beyond this range, there's no access.
by the way, in VS IDE Some tips, such as wavy lines:
Wavy line:
1) , if the red wavy line appears in your code, it means that there is a syntax error in your code.
2) If there is a green wavy line in your code, there is no error in your code syntax.
* It's just a hint that you might get an error, but it doesn't have to be an error, or a warning, or maybe you have a problem with the VS IDE , so you can try restarting Dafa.
Well, today's annotations, naming rules, access modifiers, data types, constants, variables on to this , hoping to bring help to beginners, but also hope that the great God can bring us, take us to install force, take us to fly ...
Finally, a small ad: QQ group: . NET Step by step screen number:590170361 (dabigatran Note: Blog Park to see)
. NET Foundation Step by step [annotations, naming rules, access modifiers, data types, constants, variables]