Home Subjects C# Programming

C# Programming

C# and .NET for campus placement

60 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 51–60 of 60
Topics in C# Programming
Q.51 Hard Basics & Syntax
What is the output of: int x = 10; int y = x++; Console.WriteLine(x + ", " + y);
A 10, 10
B 11, 10
C 11, 11
D 10, 11
Correct Answer:  B. 11, 10
EXPLANATION

Post-increment (x++) returns the current value before incrementing. So y = 10, then x becomes 11. Output is '11, 10'.

Test
Q.52 Hard Basics & Syntax
Which of the following correctly demonstrates method overloading in C#?
A Two methods with same name but different return types
B Two methods with same name but different parameter types or count
C Two methods with different names but same parameters
D Two methods with same signature but different access modifiers
Correct Answer:  B. Two methods with same name but different parameter types or count
EXPLANATION

Method overloading requires same method name but different parameter types, count, or order. Return type alone is insufficient for overloading.

Test
Q.53 Hard Basics & Syntax
What will be the result of: string text = null; Console.WriteLine(text ?? "Default");
A null
B Default
C NullReferenceException
D Empty string
Correct Answer:  B. Default
EXPLANATION

The null-coalescing operator (??) returns the right operand if the left is null. Since text is null, it prints 'Default'.

Test
Q.54 Hard Basics & Syntax
In C#, what is the primary purpose of the 'using' statement?
A To import namespaces
B To ensure proper resource disposal and implement IDisposable
C To declare variables
D To create aliases for types
Correct Answer:  B. To ensure proper resource disposal and implement IDisposable
EXPLANATION

The 'using' statement ensures that Dispose() is called on objects implementing IDisposable, preventing resource leaks. Importing namespaces is a different use of 'using'.

Test
Q.55 Hard Basics & Syntax
Which of the following correctly describes method overloading in C#?
A Methods must have the same name and same parameter list
B Methods can have the same name with different parameter types, count, or order
C Only the return type can differ between overloaded methods
D Method overloading is not supported in C#
Correct Answer:  B. Methods can have the same name with different parameter types, count, or order
EXPLANATION

Method overloading allows same method name with different signatures (parameter types, count, or order). Return type alone cannot differentiate overloaded methods.

Test
Q.56 Hard Basics & Syntax
What is the difference between 'struct' and 'class' in C# regarding memory allocation?
A Both are allocated on the heap
B Both are allocated on the stack
C struct is allocated on the stack, class on the heap
D struct is allocated on the heap, class on the stack
Correct Answer:  C. struct is allocated on the stack, class on the heap
EXPLANATION

Value types (struct) are allocated on the stack, while reference types (class) are allocated on the heap.

Test
Q.57 Hard Basics & Syntax
Consider: int[] arr = {1, 2, 3}; What happens when you try to resize it using Array.Resize(ref arr, 5)?
A Throws exception
B Creates new array with 5 elements, preserving first 3 values
C Returns null
D Changes original array size
Correct Answer:  B. Creates new array with 5 elements, preserving first 3 values
EXPLANATION

Array.Resize() creates a new array of specified size and copies elements from the original array using the ref parameter.

Test
Q.58 Hard Basics & Syntax
Which of the following is NOT a valid C# data type?
A sbyte
B uint
C float32
D decimal
Correct Answer:  C. float32
EXPLANATION

C# has float (4 bytes) and double (8 bytes), but not float32. sbyte, uint, and decimal are valid types.

Test
Q.59 Hard Basics & Syntax
Which of the following statements about structs and classes in C# is TRUE?
A Structs are reference types, classes are value types
B Structs are value types, classes are reference types
C Both are reference types
D Both are value types
Correct Answer:  B. Structs are value types, classes are reference types
EXPLANATION

In C#, structs are value types (stored on stack) while classes are reference types (stored on heap). This is a fundamental difference between the two.

Test
Q.60 Hard Basics & Syntax
Consider the following code. What will be the output?
int x = 10;
int y = 20;
int z = x++ + ++y;
Console.WriteLine(x + " " + y + " " + z);
A 10 20 30
B 11 21 31
C 11 21 30
D 10 21 31
Correct Answer:  B. 11 21 31
EXPLANATION

x++ returns 10 then increments x to 11. ++y increments y to 21 then returns 21. z = 10 + 21 = 31. Final output: 11 21 31

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips