.NET sixth day

1, bubble sort
int [] nums = {9,8,7,6,5,4,3,2,1,0} ; 0,1,2,3,4,5,6,7,8, 9
first trip comparison: 8765432109 exchanged nine i = 0 j = nums.Length-1-0 ;
second pass comparison: 7654321089 exchanged 8 but not the exchange comparisons i = 1 j = 8 j = nums.Length-1-1;
third Comparative Run: 6543210789 exchanged 7 times i = 2 j = 7 j = nums.Length-1-2
fourth Comparative Run: 5432106789 exchanged six times i = 3 j = 6
fifth Comparative Run: 4321056789 exchanged 5 time i = 4 j = 5
sixth Comparative Run: 3210456789 exchanged four times
seventh Comparative times: 2103456789 exchanged three times
eight times comparison: 1023456789 exchanged twice
ninth Comparative Run: 0123456789 exchange 1

for(int i=0;i<nums.Length-1;i++)
{
    for(int j=0;j<nums.Length-1-i;j++)
    {
        if(nums[j]>nums[j+1])
        {
            int temp=nums[j];
            nums[j]=nums[j+1];
            nums[j+1]=temp;
        }
    }
}

2, methods (functions)
Syntax:
[public] static return type method name ([parameter list])
{
method body;
}
public: access modifiers public, public
static: for static
Return Value Type: if none value, write void
method name: Pascal, requires first letter of each word should be capitalized.
Parameter List: complete this method, the conditions that must be provided to this method. Even if the method takes no parameters, parentheses can not be omitted.

Parameters:
Returns:

Method call:
The class name method name ([parameter list]);


. 3, return
. 1), the return value returned in the method
2), this method immediately ends


4, the relationship between the caller and the callee
us () function called Main Test () function,
we tubes Main () function is called caller tube Test () function is called by the caller.

If the caller wants to get the value of the caller:
1, pass parameters
2, declare a static field, as a "global variable" use.

If the caller wants to get the value of the caller:
1, write the return value.

Parameter: the formal parameters, will open up space in memory.
Argument: When calling a function of parameters passed.

5, when writing methods Note
1, functional approach must be single.
2, in the process as much as possible to avoid the user input prompt code like.

Guess you like

Origin www.cnblogs.com/zhengxia/p/12057586.html