#函数大概分为四种
#无参数无返回值
void main()
{
Console.WriteLine("哈哈")
}
#有参数无返回值
void deom(string str)
{
string strNum = "1"
Console.WriteLine(strNum + str)
}
#无参数有返回值
int deom()
{
int a = 10;
return a;
}
#有参数有返回值
int deom(int b)
{
int a = 10;
a += b;
return a;
}
# 参数 params
// 像下面函数参数比较多时,我们可以用params处理
pubilc void demo(int a, double c,string st, bool Isb,...)
pubilc void demo(int a, double c,params int[] value)
{
int sum = a - c;
foreach (int i in values)
{
sum = sum+i;
}
return sum;
}
# C#返回值 ref
using System;
public void demo(int b)
{
b = 20;
}
namespace ArrayApplication
{
class MyArray
{
static void Main(string[] args)
{
int b = 10;
deom(ref b); #想要更改b的值,但是发现输出还是10
Console.ReadKey();
}
}
}
#有两种方式满足上面需求1.返回值2.关键字ref
#1
public int demo(int b)
{
b = 20
return b;
}
#2
public void demo(ref int b)
{
b = 20;
}