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 151–154 of 154
Topics in C# Programming
Q.151 Medium Basics & Syntax
What is the difference between '==' and 'Equals()' when comparing strings in C#?
A '==' compares references, Equals() compares values
B '==' compares values, Equals() compares references
C Both do the same thing
D '==' is for primitive types, Equals() is for objects
Correct Answer:  A. '==' compares references, Equals() compares values
EXPLANATION

For strings, '==' compares references (memory addresses) while Equals() compares the actual string values. However, C# has optimized string comparison, so both often behave similarly for string literals.

Test
Q.152 Medium Basics & Syntax
What is the correct way to declare a constant variable in C#?
A const int MAX = 100;
B final int MAX = 100;
C static int MAX = 100;
D readonly int MAX = 100;
Correct Answer:  A. const int MAX = 100;
EXPLANATION

The 'const' keyword is used to declare constants in C#. 'final' is Java syntax. While 'readonly' can be used, 'const' is the proper keyword for compile-time constants.

Test
Q.153 Medium Basics & Syntax
Which of the following data types in C# is a value type?
A string
B int
C object
D array
Correct Answer:  B. int
EXPLANATION

int is a value type (primitive type). string, object, and arrays are reference types in C#.

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

++x is pre-increment. It increments x first (x becomes 6), then assigns the value to y. So both x and y are 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