Function: A module capable of accomplishing a function independently.
Benefits: 1. Clearer structure (easy to write and maintain). 2. Code reuse. 3. Division of Labor Development.
Four elements: Name, input (parameter), output (type of return), processing (function body)
Grammar:
type function name (argument type parameter name,....)
{
function body
}
Function call:
[Data type variable name =] Function (parameter);
When a function is called: The parameters of the call and the arguments of the function are maintained one treatment: number, type, corresponding.
Formal parameter: formal parameters. --The parameters of the function definition.
Arguments: actual parameters. --The parameters of the function call.
The law of the value of arguments and parameters--------pass the value and transmit the address.
Pass value: In integer, float, bool, char these built-in types are passed by default when the function passes parameters.
The value is passed to the parameter as a copy (copy) of the argument.
m = 30;
ADD (m);
static void Add (int a)
{
A + = 20;
}
Address: By default, an array is a pass-through, and a string is an address.
For built-in integer, floating-point, bool, char types, if you want to become the address, you need to precede the ref
m = 30;
ADD (ref m);
static void Add (ref int a)
{
A + = 20;
}
For the pass-through and the address, you should remember:
1. What is the value of the pass and what is the address? This is to be divided clearly.
2. By default, what type is the value of the pass? What types are transmitted?
3. How do I make a pass-through to the default value type? Ref
Later, in order to prevent errors due to the value of the transmission, we recommend that you use the form of the return value to explicitly return the data
Recursion--Just do the understanding.
function itself to tune itself.
static void Main (string[] args)
{
Test (0);
}
static void Test (int a)
{
If the return of the condition is very important, no words will never come out.
if (a >5)
{
Return
}
a++;
Console.WriteLine ("Is doing the first" +a+ "a Dream");
Test (a);
Console.WriteLine ("+a+", "A Dream woke up");
}
Common classes:
(a) Math class: Math
1.math.ceiling (Decimal/Integer): Returns the smallest integer greater than the current decimal. --Number of ceilings
2.math.floor (Decimal/Integer): Returns the largest integer less than the current decimal. --Number of floors
Console.WriteLine (math.ceiling (3.14)); 4
Console.WriteLine (Math.floor (3.14)); 3
Console.WriteLine (math.ceiling (3.0)); 3
3.math.pow (2,3) to evaluate the index. Equivalent to 2 of the 3-time Square
4.MATH.SQRT (16) Open square.
5. Rounding.
Math.Round (3.63); 4
Math.Round (3.14);//3
(ii) Date and time: datetime
Construct: DateTime dt = new DateTime ([1990,2,5[,3,44,21]]);
DateTime dt = new DateTime ();//?
DateTime dt = new DateTime (1990, 2, 5);//?
DateTime dt = new DateTime (1990, 2, 5, 3, 44, 25);//?
Current time:
DateTime dt = DateTime.Now;
Date-Time Object data:
Year,month,day,hour,minite,second,millisecond
dayofweek--Week. dayofyear--the first day of the year.
date--Date part of the collection period. timeofday--time period part.
Functions of DateTime objects:
AddYears (int num)
AddMonths (int num)
AddDays (int num)
AddHours (int num)
addminutes (int num)
addseconds (int num)
datetime data can be subtracted directly, returning the number of days and times between two dates.
ToString (format string) function: Displays the day in a certain format.
Format string:
yyyy--Four-digit year
yy--Two-digit year
mm--Two-digit month, less than two bits added 0
M--1-2 digits of the month
dd--Two-digit day, less than two bits added 0
D--1-2 digits of the day.
hh--
h--
mm--
m--
ss--
s--
ms--milliseconds.
For example:
DateTime dt = DateTime.Now;
Console.WriteLine (dt. ToString ("yyyy mm month DD Day hh (mm min. ss seconds"));
The ToString () function, which is more than the datetime data, can be placed in a formatted character. The integer, or decimal, of the ToString () can also be formatted as a string.
The formatting symbols for decimal and integer types are mainly four.
.--Decimal point
,—— integral part three-bit delimiter
#--any digit, several show several
0--at least one digit, not enough to fill 0.
Cases:
#.00--must retain two decimal places.
(c) string
*length: The length of the string.
ToLower (): all turned into lowercase
ToUpper (): all turned into uppercase
TrimStart ():
TrimEnd ():
Trim (): A space at the ends of the press.
*startswidth ("string"): whether (BOOL) begins with the enclosed string, yes--returns TRUE.
*endswidth ("string"): whether (bool) ends with a string in parentheses, yes--returns TRUE.
*contains ("string"): (bool) whether the string in parentheses is included. Yes-returns TRUE.
*indexof ("substring"): (int) Returns the position of the substring in the first occurrence of the string.
*lastindexof ("substring"): (int) Returns the last occurrence of a substring in a string.
The above two functions, if the corresponding substring is not found in the string, return-1
*substring (int start[,int length]): (string) intercepts substrings.
Replace (String old,string New): (string) The old swop of the string into a new string
*split (' character '): (string[]) The elements in the array are taken apart by the characters in parentheses.
C#. 5 function classes