首页 / 软件开发 / C# / C#语法练习(8): 函数
C#语法练习(8): 函数2011-09-22 博客园 万一无参、无返回值的函数:using System;
class MyClass
{
static void Show()
{
Console.WriteLine("function");
}
static void Main()
{
Show(); //function
Console.ReadKey();
}
}
参数:using System;
class MyClass
{
static void Show(string str)
{
Console.WriteLine("is " + str);
}
static void Main()
{
show("function"); //is function
Console.ReadKey();
}
}
返回值:using System;
class MyClass
{
static string Show(string str)
{
return "is " + str;
}
static void Main()
{
string s = Show("function");
Console.WriteLine(s); //is function
Console.ReadKey();
}
}