函数简介

函数:

函数写在program下面,void表示没有返回值,()中的东西表示参数

1.没有返回值没有参数

public void aa()

{

}

2.有参数没有返回值

public void aa(int a)

{

}

3.有返回值没有参数

public double aa()

{

}

4.有返回值有参数

public double aa(int a)

{

}

public表示函数是公用的,其他cs里也可以引用

用法:

program b=new program();

b.aa();

 1   class Program
 2     {
 3               public double max(double a, double b)
 4         {
 5             if (a > b)
 6             {
 7                 return a;
 8             }
 9             else
10             {
11                 return b;
12             }
13        }
14 
15 
16  static void Main(string[] args)
17         {           
18             Console.Write("请输入第一个个数字:");
19             double a = int.Parse(Console.ReadLine());
20             Console.Write("请输入第二个个数字:");
21             double b = int.Parse(Console.ReadLine());
22             Console.Write("请输入第三个个数字:");
23             double c = int.Parse(Console.ReadLine());
24             Program daxiao = new Program();
25             double d = daxiao.max(c, daxiao.max(a, b));
26             Console.Write(d);
27         }
28     }
原文地址:https://www.cnblogs.com/mazhijie/p/5483840.html