C# banner

C# Multiple Choice Questions (MCQs) and Answers

Master C# with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of C# concepts. Begin your placement preparation journey now!

Q31

Q31 How do you define an array of integers in C#?

A

int[] numbers = new int[5];

B

int numbers = new int[5];

C

int[5] numbers;

D

int array[5];

Q32

Q32 You get an 'unassigned local variable' error.
What is the likely cause?

A

Variable declared but not initialized

B

Incorrect data type

C

Using a reserved keyword

D

Incorrect syntax

Q33

Q33 You get a 'cannot implicitly convert type' error.
What might be the cause?

A

Trying to assign a float to an int

B

Missing semicolon

C

Incorrect method definition

D

Using a reserved keyword

Q34

Q34 What does the '==' operator do in C#?

A

Compares values for equality

B

Assigns value

C

Compares references

D

None of the above

Q35

Q35 Which operator is used to concatenate strings in C#?

A

=+

B

&

C

*

D

&&

Q36

Q36 What is the result of '10 / 3' in C#?

A

3.33

B

3

C

4

D

3.0

Q37

Q37 What does the '&&' operator do in C#?

A

Logical AND

B

Logical OR

C

Bitwise AND

D

Bitwise OR

Q38

Q38 What is the output of '5 + 2 * 3' in C#?

A

21

B

11

C

10

D

7

Q39

Q39 How do you increment a variable 'x' by 1 in C#?

A

x = x + 1;

B

x += 1;

C

x++;

D

All of the above

Q40

Q40 What is the result of '15 % 4' in C#?

A

3

B

4

C

1

D

2

Q41

Q41 How do you write a conditional expression that checks if 'x' is greater than 'y' in C#?

A

if (x > y) { }

B

if x > y then { }

C

if (x > y) then { }

D

if x > y { }

Q42

Q42 You get a 'Division by zero' runtime error.
What is the likely cause?

A

Dividing an integer by zero

B

Multiplying two large integers

C

Using uninitialized variables

D

Accessing array elements out of bounds

Q43

Q43 You get an 'invalid expression' error when using operators.
What could be the issue?

A

Missing operand

B

Using reserved keywords

C

Incorrect syntax

D

All of the above

Q44

Q44 What might cause a 'type mismatch' error in an expression?

A

Mixing data types in an expression

B

Using incorrect variable names

C

Incorrect function call

D

Syntax errors

Q45

Q45 Which keyword is used to exit a loop prematurely in C#?

A

exit

B

stop

C

break

D

return

Q46

Q46 Which of the following is a conditional statement in C#?

A

for

B

while

C

if

D

do

Q47

Q47 What is the purpose of the 'continue' keyword in loops?

A

Exit the loop

B

Skip the current iteration and continue with the next

C

End the program

D

None of the above

Q48

Q48 Which loop is guaranteed to execute at least once?

A

for

B

while

C

do-while

D

foreach

Q49

Q49 How do you define a switch statement in C#?

A

switch (variable) { case value: break; }

B

switch (variable) { case value; break; }

C

switch variable { case value: break; }

D

switch variable { case value; break; }

Q50

Q50 How do you write an 'if-else' statement in C#?

A

if (condition) { // code } else { // code }

B

if condition: { // code } else: { // code }

C

if condition then { // code } else then { // code }

D

if (condition) { // code } otherwise { // code }

Q51

Q51 How do you write a 'for' loop in C#?

A

for (int i = 0; i < 10; i++) { }

B

for (int i = 0; i < 10) { }

C

for i in range(10): { }

D

for i = 0 to 9 { }

Q52

Q52 How do you write a 'while' loop in C#?

A

while (condition) { // code }

B

while condition: { // code }

C

while (condition) then { // code }

D

while condition { // code }

Q53

Q53 Your 'if' statement always executes the 'else' part.
What could be the issue?

A

Incorrect condition

B

Missing braces

C

Variable scope issue

D

Using 'else if' instead of 'else'

Q54

Q54 You encounter an infinite loop in your code.
What is the most likely cause?

A

Incorrect loop condition

B

Missing return statement

C

Variable scope issue

D

Syntax error

Q55

Q55 You get a 'case label not within a switch statement' error.
What might be the cause?

A

Case label used outside switch statement

B

Incorrect case value

C

Missing break statement

D

Incorrect syntax

Q56

Q56 What is the correct way to declare a single-dimensional array in C#?

A

int[] arr;

B

int arr[];

C

int[10] arr;

D

int arr;

Q57

Q57 What is the index of the first element in a C# array?

A

0

B

1

C

-1

D

It depends on the array size

Q58

Q58 Which collection type is ordered and allows duplicate elements?

A

Dictionary

B

HashSet

C

List

D

Queue

Q59

Q59 What method is used to add an element to a List in C#?

A

Add()

B

Insert()

C

Append()

D

Push()

Q60

Q60 Which of the following is true about arrays and collections in C#?

A

Arrays are dynamic, collections are static

B

Arrays can store elements of different types, collections cannot

C

Collections provide more flexibility and functionality than arrays

D

Arrays are always passed by reference

ad verticalad vertical
ad