void Keyword in C#

Keywords are the words in a language that are used for some internal process or represent some predefined actions. void is a keyword, it is a reference type of data type and used to specify the return type of a method in C#. It is an alias of System.Void.

Syntax:

public void function_name([parameters])
{
    //body of the function
}

Note: void cannot be used as a parameter if there is no parameter in a C# method.

Example:

Input: Geeks
       multi = 50*20

Output: Geeks
        multi = 1000

Output: GeeksforGeeks
        sum = 80+20
        sub = 40-10

Output: GeeksforGeeks
        sum = 100
        sub = 30

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for void keyword
using System;
class GFG {
  
    public void SimpleText()
    {
        Console.WriteLine("Geeks");
    }
  
    public void sum(int a, int b)
    {
        Console.WriteLine("multi = " + (a * b));
    }
};
  
class Prog {
  
    static void Main(string[] args)
    {
        // calling functions
        GFG ex = new GFG();
        ex.SimpleText();
        ex.sum(50, 20);
    }
}

chevron_right


Output:

Geeks
multi = 1000

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program for void keyword
using System;
using System.Text;
  
namespace Test {
  
class Sample {
  
    public void SimpleText()
    {
        Console.WriteLine("GeeksforGeeks");
    }
  
    public void sum(int a, int b)
    {
        Console.WriteLine("sum = " + (a + b));
    }
  
    public void sub(int c, int d)
    {
        Console.WriteLine("sub = " + (c - d));
    }
};
  
class Prog {
  
    static void Main(string[] args)
    {
        // calling functions
        Sample ex = new Sample();
        ex.SimpleText();
        ex.sum(80, 20);
        ex.sub(40, 10);
  
        // hit ENTER to exit
        Console.ReadLine();
    }
}
}

chevron_right


Output:

GeeksforGeeks
sum = 100
sub = 30



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.