Home Subjects C# Programming

C# Programming

C# and .NET for campus placement

154 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 131–140 of 154
Topics in C# Programming
Q.131 Medium Basics & Syntax
What is the correct way to check if a string is null or empty in modern C#?
A string.IsNullOrEmpty(str)
B string.IsNullOrWhiteSpace(str)
C str == null || str.Length == 0
D Both A and C are correct
Correct Answer:  D. Both A and C are correct
EXPLANATION

Both methods work correctly. IsNullOrEmpty checks for null or empty, IsNullOrWhiteSpace also considers whitespace.

Test
Q.132 Medium Basics & Syntax
How many dimensions does a jagged array have in the following declaration: int[][] arr;
A One
B Two
C Three
D Undefined
Correct Answer:  B. Two
EXPLANATION

int[][] is a two-dimensional jagged array where each element is an array of integers of potentially different lengths.

Test
Q.133 Medium Basics & Syntax
Which access modifier provides access within the same assembly only?
A public
B private
C internal
D protected
Correct Answer:  C. internal
EXPLANATION

'internal' modifier allows access within the same assembly but not from external assemblies.

Test
Q.134 Medium Basics & Syntax
Which of the following correctly demonstrates nullable type syntax in C#?
A int? x = null;
B nullable x = null;
C int x? = null;
D int* x = null;
Correct Answer:  A. int? x = null;
EXPLANATION

The correct syntax for nullable types is 'type?' where ? makes the value type nullable, allowing null values.

Test
Q.135 Medium Basics & Syntax
What will be the output of: sbyte x = -128; sbyte y = x - 1; Console.WriteLine(y);
A -129
B 127
C overflow exception
D compilation error
Correct Answer:  B. 127
EXPLANATION

sbyte range is -128 to 127. When overflow occurs without checked context, it wraps around to 127.

Test
Q.136 Medium Basics & Syntax
What will be the output of: int x = 10; int y = x; y = 20; Console.WriteLine(x);
A 10
B 20
C Compilation error
D Cannot determine
Correct Answer:  A. 10
EXPLANATION

int is a value type. When y = x, a copy of x's value is assigned to y. Changing y doesn't affect x.

Test
Q.137 Medium Basics & Syntax
What is the purpose of the 'using' statement in C#?
A To import namespaces only
B To automatically dispose of resources implementing IDisposable
C To create aliases for types
D Both A and B
Correct Answer:  D. Both A and B
EXPLANATION

using serves two purposes: importing namespaces and automatically disposing resources through IDisposable pattern.

Test
Q.138 Medium Basics & Syntax
Which of the following correctly declares a jagged array?
A int[,] arr = new int[3][4];
B int[][] arr = new int[3][];
C int[,] arr = new int[3,4];
D int[] arr = new int[3][4];
Correct Answer:  B. int[][] arr = new int[3][];
EXPLANATION

Jagged arrays use [][] syntax. [,] is for multidimensional arrays. int[][] allows arrays of varying lengths.

Test
Q.139 Medium Basics & Syntax
What is the output of: Console.WriteLine(5 == 5.0);
A True
B False
C Compilation error
D Cannot compare
Correct Answer:  A. True
EXPLANATION

C# allows comparison between int and double. 5 and 5.0 are numerically equal, so == returns True.

Test
Q.140 Medium Basics & Syntax
Which access modifier allows access from derived classes only?
A private
B public
C protected
D internal
Correct Answer:  C. protected
EXPLANATION

protected members are accessible from the same class and derived classes, but not from outside the class hierarchy.

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