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 101–110 of 154
Topics in C# Programming
Q.101 Medium Basics & Syntax
Which of the following statements about ref and out parameters in C# is correct?
A ref parameter must be initialized before passing, out parameter need not be
B out parameter must be initialized before passing, ref parameter need not be
C Both ref and out require initialization before method call
D Neither ref nor out requires initialization
Correct Answer:  A. ref parameter must be initialized before passing, out parameter need not be
EXPLANATION

ref parameters must be initialized before being passed to a method, while out parameters don't require initialization beforehand. The method must assign a value to out parameters before returning.

Test
Q.102 Medium Basics & Syntax
Which of the following correctly demonstrates the ternary operator in C#?
A int x = (age >= 18) ? "adult" : "minor";
B int x = (age >= 18) ? 1 : 0;
C bool x = (age >= 18) ? true; false;
D string x = (age >= 18) ? 18 : 0;
Correct Answer:  B. int x = (age >= 18) ? 1 : 0;
EXPLANATION

Option B is correct as both branches return int (1 or 0). Option A has type mismatch (string in int). Option C has wrong syntax. Option D has type mismatch.

Test
Q.103 Medium Basics & Syntax
Which statement about method overloading in C# is correct?
A Methods can have the same name if they differ in return type only
B Methods can have the same name if they differ in parameter types or count
C Method overloading is not supported in C#
D Methods must have different access modifiers to be overloaded
Correct Answer:  B. Methods can have the same name if they differ in parameter types or count
EXPLANATION

Method overloading requires different parameter types, count, or order. Return type alone is not enough. C# fully supports overloading.

Test
Q.104 Medium Basics & Syntax
What is the output of: char ch = 'A'; Console.WriteLine((int)ch);
A 65
B A
C 1
D 97
Correct Answer:  A. 65
EXPLANATION

char 'A' has ASCII value 65. Casting to int gives the numeric ASCII value.

Test
Q.105 Medium Basics & Syntax
Which of the following is true about the 'var' keyword in C#?
A var can hold any type of data without type checking
B var is explicitly typed at compile-time based on initialization
C var is dynamically typed like in Python
D var can be used for global variables only
Correct Answer:  B. var is explicitly typed at compile-time based on initialization
EXPLANATION

var is implicitly typed. The type is inferred and set at compile-time based on the right-hand side assignment, providing type safety.

Test
Q.106 Medium Basics & Syntax
Which keyword is used to create a constant variable in C# that cannot be changed?
A const
B readonly
C static
D fixed
Correct Answer:  A. const
EXPLANATION

const creates a compile-time constant. readonly allows assignment only in constructor or at declaration. static makes it class-level, and fixed is for pointers.

Test
Q.107 Medium 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 first, then increments. So y gets 10, then x becomes 11.

Test
Q.108 Medium Basics & Syntax
What is the main purpose of the 'finally' block in C#?
A To catch exceptions
B To execute code whether an exception occurs or not
C To throw custom exceptions
D To define exception handlers
Correct Answer:  B. To execute code whether an exception occurs or not
EXPLANATION

The 'finally' block executes regardless of whether an exception is thrown or caught. It is used for cleanup operations like closing file streams or database connections.

Test
Q.109 Medium Basics & Syntax
Which of the following best describes LINQ in C#?
A A type of loop statement
B Language Integrated Query for data manipulation
C A database connection protocol
D A type of exception handling mechanism
Correct Answer:  B. Language Integrated Query for data manipulation
EXPLANATION

LINQ (Language Integrated Query) provides a unified syntax for querying different data sources like collections, databases, XML, etc. It allows developers to write queries in C# syntax.

Test
Q.110 Medium Basics & Syntax
What is the purpose of the 'abstract' keyword in C#?
A To prevent inheritance of a class
B To create a class that cannot be instantiated directly
C To make all methods virtual
D To restrict access to private members
Correct Answer:  B. To create a class that cannot be instantiated directly
EXPLANATION

'abstract' keyword creates a class that serves as a blueprint for derived classes and cannot be instantiated directly. Abstract classes can contain abstract methods that must be implemented by derived classes.

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