第二十节 函数
函数:是一段被封装起来的能实现一定功能的代码。
函数的签名:指明了函数的名称,参数,返回值类型。
函数体:函数的具体实现代码定义在签名后的一对大括号中。
函数的命名方式。所有的首字母大写。
如果在函数A()中调用函数B()A()为主调函数,B()为被调函数。
return 语句注意一下几点。
1.返回值类型和定义类型一致。
2.可以用return 返回表达式。 eg:(x>y)?x:y;
3.函数中可以有多个return语句,先执行哪个,就哪个起作用。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Da
{
class Program
{
static double Bigger(double x, double y)
{
double MaxVlue = (x > y) ? x : y;
return MaxVlue;
}
static void Main(string[] args)
{
double result;
result = Bigger(5,100);
Console.WriteLine("最大数为{0}",result);
}
}
}
浙公网安备 33010602011771号