. NET basic step by step: [methods, structures, enumeration],. net basic structure Enumeration
Methods, structures, and enumeration
Method:
A mechanism for reusing a bunch of code.
Syntax:
[Access modifier] return type <Method Name> (parameter list ){
Method subject;
}
Return Value Type: if you do not need to write the return value, write void
Method Name: Pascal has a higher initial letter for each word. Lowercase letters
Parameter list: the conditions that must be provided to this method to complete this method. If no parameter exists, parentheses are not omitted.
After writing the method, you must call it if you want to be executed.
Method call Syntax: Class Name. Method Name (parameter );
Case:
Structure:
Declare multiple variables of different types at a time. A custom data type. You can define a method internally, which belongs to the value type.
Syntax:
Access modifier struct structure name {member; // field}
Case:
I:
II:
Enumeration:
A group of named numeric constants used to define data types with a specific set of values.
Syntax:
Access modifier enum enumeration name {Value List}
Enumeration is a variable type, int -- double string decimal.
Only enumeration declaration, value assignment, and usage are different from those of common variable types.
We can convert an enumerated type variable to an int type or a string type.
The enumeration type is compatible with the int type by default. Therefore, you can use the syntax of forced type conversion to convert each other.
When you convert a value that is not in an enumeration, the number is displayed directly instead of an exception.
Enumeration can also be converted to the string type. If you convert the enumeration type to the string type, you can directly call ToString ().
To convert a string to an enumeration type, you need the following code:
(Enumeration type to be converted) Enum. Parse (typeof (Enumeration type to be converted), "string to be converted ");
If the string to be converted is a number, it will not throw an exception even if it is not in the enumeration.
If the converted string is text, if it is not in the enumeration, an exception is thrown.
Case:
I:
II:
III:
Well, this article is here, and the case provided in this article is only, there is no running result, please handle it yourself. I hope it will help beginners. I also hope that the great gods will take us with us, pack us with force, and fly us with us...
Finally, make a small advertisement: QQ group:. NET Step by stepGroup Number:590170361(Add group remarks: what you see in the blog Park)