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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.