×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# void Keyword with Example

In this tutorial, we will learn about the void keyword, its usage, syntax, and example in C#. By IncludeHelp Last updated : April 04, 2023

C# void Keyword

In C#, void keyword is a reference type of data type, it is used to specify the return type of a method in C#. The void is an alias of System.Void.

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

Syntax of void

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

Example of void keyword in C#

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

Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.