ExamVeda
Login
Home
11
What does the 'void' keyword indicate in C#?
Discuss
Answer & 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".
12
Which of the following is a correct way to declare a variable in C#?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
13
What is the default access modifier for class members in C#?
Discuss
Answer & Solution
Answer: Option C
Solution:
The correct answer is C: private.
Let's understand why:
* Access Modifiers control the visibility and accessibility of class members (like variables and methods).
* `public`: Means any code can access the member.
* `private`: Means only code within the same class can access the member.
* `protected`: Means the class itself and any classes that inherit from it (subclasses) can access the member.
* `internal`: Means code within the same assembly (a compiled set of code, like a .exe or .dll) can access the member.
If you don't explicitly specify an access modifier (like `public`, `private`, etc.) for a class member in C#, C# automatically assigns it the `private` access modifier.
This is a design choice to promote encapsulation - hiding the internal workings of a class and controlling access to its data. It makes the code more organized and maintainable.
14
What is the correct syntax to create a new instance of a class in C#?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
15
Which of the following statements is true about C#?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
16
What is the latest version of C# as of 2023?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
17
Which of the following is NOT a C# access modifier?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
18
In C#, what keyword is used to declare a constant?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
19
Which of the following statements is true about namespaces in C#?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
20
What is the default value of an int in C# if not explicitly initialized?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board