Home »
C#.Net
void keyword in C#
C# void keyword: Here, we are going to learn about the void keyword in C#, what is void keyword, how to use it n C#?
Submitted by IncludeHelp, on March 07, 2019
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#.
void keyword is an alias of System.Void.
Note: If there is no parameter in a C# method, void cannot be used as a parameter.
Syntax:
public void function_name([parameters])
{
//body of the function
}
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