Vidyalelo
C# Programming · Q11

Introduction to C Sharp

Programming · C# Programming · question 11

Q11

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

A.
It does not return a value
Answer
B.
It returns a value
C.
It indicates an error
D.
It is a data type

Answer: Option A

Solution

Answer: Option A
Solution:
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".