Home Subjects C# Programming Basics & Syntax

C# Programming
Basics & Syntax

C# and .NET for campus placement

56 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 31–40 of 56
Topics in C# Programming
Q.31 Medium Basics & Syntax
What happens when you try to access an array element beyond its length in C#?
A Returns null
B Returns default value of the type
C Throws IndexOutOfRangeException
D Returns the last element
Correct Answer:  C. Throws IndexOutOfRangeException
EXPLANATION

Accessing an array index beyond its bounds throws an IndexOutOfRangeException at runtime.

Test
Q.32 Medium Basics & Syntax
Which of the following statements about properties in C# is TRUE?
A Properties can only have get accessors
B Properties can have get and/or set accessors with different access levels
C Properties cannot be overridden
D Properties must have both get and set accessors
Correct Answer:  B. Properties can have get and/or set accessors with different access levels
EXPLANATION

Properties can have get and set accessors independently with different access modifiers like public get, private set.

Test
Q.33 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.34 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.35 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.36 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.37 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.38 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.39 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.40 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
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