Examveda

What does the 'void' keyword indicate in C#?

A. It does not return a value

B. It returns a value

C. It indicates an error

D. It is a data type

Answer: Option A

Solution (By Examveda Team)

void is a return type in C# that specifies a method does not return any value.

When you define a method in C#, you must declare what type of value it will return using a return type. If the method performs some actions but does not return a result to the calling code, you use void as the return type.

For example:

Example:
void PrintGreeting()
{
    Console.WriteLine("Hello, World!");
}


In this example, the method PrintGreeting() simply prints a message to the console and does not return any value.

If you try to use a return statement with a value in a void method, the compiler will throw an error, because void means "no return value".

Important Notes:

Use void when your method does something but doesn't produce a result.

void is commonly used in event handlers, logging methods, and other utility functions.

Unlike data types like int, string, or bool, void represents the absence of a return value, not a data type.

Therefore, Option A is correct: "It does not return a value".

This Question Belongs to C Sharp Programming >> Introduction To C Sharp

Join The Discussion

Comments (1)

  1. Basant Anand
    Basant Anand:
    1 year ago

    How it will be an error i think you guys are providing wrong info.

Related Questions on Introduction to C Sharp