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 11–20 of 56
Topics in C# Programming
Q.11 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.12 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
Q.13 Medium Basics & Syntax
Which collection type in C# maintains insertion order and allows duplicate elements?
A HashSet
B Dictionary
C List
D SortedSet
Correct Answer:  C. List
EXPLANATION

List<T> maintains insertion order and allows duplicates. HashSet<T> doesn't allow duplicates. Dictionary<K,V> maintains key-value pairs. SortedSet<T> keeps elements sorted without duplicates.

Test
Q.14 Medium Basics & Syntax
What will be the output of: string s1 = "Hello"; string s2 = "Hello"; Console.WriteLine(s1 == s2);
A true
B false
C null
D Error
Correct Answer:  A. true
EXPLANATION

In C#, the == operator for strings compares their values, not references. Since both s1 and s2 contain "Hello", the result is true. This is different from object references comparison.

Test
Q.15 Medium Basics & Syntax
In C#, what does the 'params' keyword allow you to do?
A Pass parameters by reference
B Accept a variable number of arguments of the same type
C Define optional parameters
D Declare parameters with default values
Correct Answer:  B. Accept a variable number of arguments of the same type
EXPLANATION

'params' allows a method to accept a variable number of arguments of the same type as an array. For example: void Method(params int[] numbers) can accept 0 or more integers.

Test
Q.16 Medium Basics & Syntax
Which of the following is a nullable type in C#?
A int?
B Nullable
C Both A and B are equivalent
D Neither A nor B can be nullable
Correct Answer:  C. Both A and B are equivalent
EXPLANATION

Both int? and Nullable<int> represent the same nullable integer type. int? is the shorthand syntax for Nullable<int>. They allow the variable to hold a null value in addition to integer values.

Test
Q.17 Medium Basics & Syntax
Which method is used to convert a string to an integer in C#?
A string.ToInteger()
B int.Parse() or int.TryParse()
C Convert.ToInt32()
D Both B and C are correct
Correct Answer:  D. Both B and C are correct
EXPLANATION

Both int.Parse() and Convert.ToInt32() can convert strings to integers. int.TryParse() is safer as it returns a boolean indicating success/failure. All are valid approaches.

Test
Q.18 Medium Basics & Syntax
In C#, what is the difference between 'struct' and 'class'?
A struct is a reference type, class is a value type
B struct is a value type, class is a reference type
C There is no difference; they are synonymous
D struct supports inheritance, class does not
Correct Answer:  B. struct is a value type, class is a reference type
EXPLANATION

struct is a value type stored on the stack, while class is a reference type stored on the heap. struct does not support inheritance from other structs/classes (except interfaces), while classes do.

Test
Q.19 Medium Basics & Syntax
Which of the following correctly demonstrates string interpolation in C# 6.0 and above?
A string name = "John"; Console.WriteLine("Hello " + name);
B string name = "John"; Console.WriteLine(string.Format("Hello {0}", name));
C string name = "John"; Console.WriteLine($"Hello {name}");
D string name = "John"; Console.WriteLine(@"Hello {name}");
Correct Answer:  C. string name = "John"; Console.WriteLine($"Hello {name}");
EXPLANATION

String interpolation uses the \( prefix with curly braces to embed expressions. Option C shows the correct syntax: \)"Hello {name}". The @ symbol creates verbatim strings, not interpolated strings.

Test
Q.20 Medium Basics & Syntax
What will be the output of the following code? int a = 5; int b = ++a; Console.WriteLine(a + " " + b);
A 5 5
B 6 6
C 6 5
D 5 6
Correct Answer:  B. 6 6
EXPLANATION

++a is pre-increment, which increments 'a' to 6 first, then assigns it to 'b'. So both a and b become 6. Output is '6 6'.

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