C # learning notes (3) Functions

Source: Internet
Author: User

15th talking about Functions

Function: Given the value of the independent variable, you can get the function value.

ProgramFunctions in design:

Function;
Parameters;
Return value;

All meaningful functions have functions;
A function is a function module;
Writing a function actually isolates a function module.

1. Max is the maximum value.
2. Calculate the area with the given radius of cirarea

Max must have two parameters: num1 and num2. return values: the maximum value.
Cirarea must have the parameter r returned value: Area

Function call
Use Functions

 

Code:

Public partial class form1: FORM {
Public form1 (){
Initializecomponent ();
}
// The load time processing function of the Main Window cannot be called only by the operating system.
Private void form1_load (Object sender, eventargs e ){
/*
Int A = 13;
Int B = 14;
Int y = max (A, B );
This. textbox1.text = Y. tostring ();
//*/
/*
Int r = 13;
Float area = cirarea (R );
This. textbox1.text = area. tostring ();
//*/
}
// The function of the Max function is: a large number of outputs.
Private int max (INT num1, int num2 ){
If (num1> = num2 ){
Return num1;
}
Else {
Return num2;
}
}
// Calculate the area of the circle
Private float cirarea (int r ){
Const float Pi = 3.14f;
Float area = 0;

Area = pI * r * R;
Return area;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.