c#基础知识第七节

class Program
{
//定义没有返回值的方法
static void PrintName(string name)
{
Console.WriteLine("你的姓名是" + name);
}
//定义有返回值的方法
static string GetFullName(string fristName, string lastName)
{
return fristName + "" + lastName;
}
static void Main(string[] args)
{
//调用没有返回值的方法
Program.PrintName("张三");

//调用有返回值的方法
string name = Program.GetFullName("张","三");
Console.WriteLine(name);

}
}

方法和参数

[修饰符]  返回值类型  方法名([ [ 参数类型  参数名1 ],[ 参数类型   参数名2] ,]...)

{

  方法体

  return 返回值;

}

有返回值方法,一旦得到调用后就会得到一个值。

原文地址:https://www.cnblogs.com/zhang1997/p/7646807.html