c#中void
C#void关键字 (C# void keyword)
In C#, void is a keyword. a void is a reference type of data type, it is used to specify the return type of a method in C#.
在C#中, void是关键字。 void是数据类型的引用类型,它用于指定C#中方法的返回类型。
void keyword is an alias of System.Void.
void关键字是System.Void的别名。
Note: If there is no parameter in a C# method, void cannot be used as a parameter.
注意:如果C#方法中没有参数,则不能将void用作参数。
Syntax:
句法:
public void function_name([parameters])
{
//body of the function
}
C#代码演示void关键字示例 (C# code to demonstrate example of void keyword)
using System;
using System.Text;
namespace Test
{
class Example
{
public void printText()
{
Console.WriteLine("Hello world!");
}
public void sum(int a, int b)
{
Console.WriteLine("sum = " + (a + b));
}
};
class Program
{
static void Main(string[] args)
{
//calling functions
Example ex = new Example();
ex.printText();
ex.sum(10, 20);
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
输出量
Hello world!
sum = 30
翻译自: https://www.includehelp.com/dot-net/void-keyword-in-c-sharp.aspx
c#中void