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 41–50 of 56
Topics in C# Programming
Q.41 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.42 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
Q.43 Medium Basics & Syntax
Which of the following statements about abstract classes is correct?
A Cannot contain abstract methods
B Can be instantiated directly
C Can contain non-abstract methods and properties
D All abstract class members must be abstract
Correct Answer:  C. Can contain non-abstract methods and properties
EXPLANATION

Abstract classes can contain both abstract and non-abstract (concrete) methods and properties. They cannot be instantiated directly.

Test
Q.44 Medium Basics & Syntax
What is the output of: int x = 5; Console.WriteLine(x++);
A 5
B 6
C Compilation error
D Cannot determine
Correct Answer:  A. 5
EXPLANATION

x++ is post-increment, so it returns the current value (5) before incrementing. The next Console.WriteLine would print 6.

Test
Q.45 Medium Basics & Syntax
What will happen if you try to access an array element beyond its bounds?
A Returns default value
B Throws IndexOutOfRangeException
C Returns null
D Compilation error
Correct Answer:  B. Throws IndexOutOfRangeException
EXPLANATION

Accessing array elements beyond bounds throws IndexOutOfRangeException at runtime.

Test
Q.46 Medium Basics & Syntax
What is the difference between 'var' and explicit type declaration in C#?
A var creates a dynamic variable
B var is implicitly typed but strongly typed at compile time
C var has no type checking
D var cannot be used in loops
Correct Answer:  B. var is implicitly typed but strongly typed at compile time
EXPLANATION

var is implicitly typed, meaning the compiler infers the type at compile time, but it's still strongly typed. It's not dynamic.

Test
Q.47 Medium Basics & Syntax
Which keyword is used to create an immutable class member in C#?
A static
B readonly
C const
D sealed
Correct Answer:  B. readonly
EXPLANATION

readonly keyword prevents reassignment of a field after initialization. const is for compile-time constants, static for class-level, sealed for inheritance prevention.

Test
Q.48 Medium Basics & Syntax
What will happen when you try to access an array index that is out of bounds in C#?
A Returns null
B Returns 0
C Throws IndexOutOfRangeException
D Returns undefined value
Correct Answer:  C. Throws IndexOutOfRangeException
EXPLANATION

Accessing an array element beyond its bounds throws an IndexOutOfRangeException at runtime. This is a safety feature to prevent accessing invalid memory.

Test
Q.49 Medium Basics & Syntax
Which keyword is used to prevent a class from being inherited in C#?
A final
B sealed
C abstract
D static
Correct Answer:  B. sealed
EXPLANATION

'sealed' keyword prevents a class from being inherited in C#. 'final' is Java syntax. 'abstract' requires a class to be inherited. 'static' makes members class-level, not related to inheritance.

Test
Q.50 Medium Basics & Syntax
What is the output of the following code?
bool result = (5 > 3) && (2 < 1);
Console.WriteLine(result);
A true
B false
C Error
D null
Correct Answer:  B. false
EXPLANATION

(5 > 3) is true, but (2 < 1) is false. The '&&' (AND) operator returns true only if both conditions are true. Since one is false, the result is false.

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