C Sharp中的功能

C Sharp中的功能

问题描述:

如何在C#中声明函数?

How do I declare functions in C#?

开始 ^ ]读取所有内容.
Start here[^] read everything.


所有函数都是类的一部分,通常称为方法.

All functions are part of a class, they''re usually called methods.

private/public int myMethod (int param);



此方法将一个int作为输入并返回一个int.

干杯



This method takes an int as input and returns an int.

Cheers


[修饰符] [返回类型] [功能名称](parm)
{
//在这里编写代码
}

public int add(int a,int b)
{
int sum = a + b;
返回总和;
}
[modifier] [return type] [founction name](parm)
{
// write code here
}
ie
public int add(int a,int b)
{
int sum=a+b;
return sum;
}