C# void keyword: Here, we will find out about the void keyword in C#, what is the void keyword, how to utilize it n C#?
C# void keyword
In C#, the void is a keyword. a void is a reference sort of information type, it is utilized to indicate the arrival kind of a strategy in C#.
void keyword is a nom de plume of System.Void.
Note: If there is no parameter in a C# technique, void can’t be utilized as a parameter.
Syntax:
public void function_name([parameters])
{
//body of the function
}
C# code to exhibit an 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