Home Subjects C# Programming Basics & Syntax

C# Programming
Basics & Syntax

C# and .NET for campus placement

29 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 1–10 of 29
Topics in C# Programming
Which of the following is a correct way to declare a property with auto-implementation in C#?
A public int Age { get; set; }
B public int Age() { get; set; }
C public Age int { get; set; }
D public int get Age; set;
Correct Answer:  A. public int Age { get; set; }
EXPLANATION

Auto-implemented properties in C# use the syntax: public Type PropertyName { get; set; } without explicitly defining the backing field.

Test
Consider this code: int[] arr = new int[5]; foreach(var item in arr) { Console.Write(item + " "); } What is the output?
A Nothing (empty output)
B 0 0 0 0 0
C Throws an IndexOutOfRangeException
D Null Null Null Null Null
Correct Answer:  B. 0 0 0 0 0
EXPLANATION

Arrays in C# are automatically initialized with default values. For int arrays, the default value is 0. Therefore, the output will be five zeros separated by spaces.

Test
Which collection type in C# is best suited for key-value pair storage with unique keys?
A List
B Dictionary
C HashSet
D Queue
Correct Answer:  B. Dictionary
EXPLANATION

Dictionary<K, V> stores key-value pairs and ensures unique keys. List stores ordered values, HashSet stores unique values only, Queue is FIFO.

Test
What will be the result of: Console.WriteLine(10 / 3);
A 3.33333
B 3.33
C 3
D 3.0
Correct Answer:  C. 3
EXPLANATION

Since both 10 and 3 are integers, integer division occurs, resulting in 3 (the decimal part is truncated).

Test
Which of the following correctly declares and initializes an array in C#?
A int[] arr = new int[5] {1, 2, 3, 4, 5};
B int arr[5] = {1, 2, 3, 4, 5};
C int[] arr(5) = {1, 2, 3, 4, 5};
D array int[] arr = new int[5];
Correct Answer:  A. int[] arr = new int[5] {1, 2, 3, 4, 5};
EXPLANATION

Option A is the correct C# syntax. Option B is C-style, Option C has wrong syntax, and Option D has incorrect keyword placement.

Test
Which of the following is NOT a value type in C#?
A int
B string
C float
D bool
Correct Answer:  B. string
EXPLANATION

string is a reference type in C#, while int, float, and bool are value types.

Test
What is the output of: bool result = (5 > 3) && (3 < 2); Console.WriteLine(result);
A true
B false
C null
D Error
Correct Answer:  B. false
EXPLANATION

The && operator requires both conditions to be true. (5 > 3) is true, but (3 < 2) is false. Since one condition is false, the entire expression evaluates to false.

Test
Which statement correctly describes value types in C#?
A Value types are stored on the heap
B Value types are stored on the stack
C Value types require null checking
D Value types can be inherited
Correct Answer:  B. Value types are stored on the stack
EXPLANATION

Value types (int, double, struct, etc.) are stored on the stack memory. Reference types (class, interface) are stored on the heap. Value types don't require null checks like reference types.

Test
What is the default access modifier for a class member in C# if not explicitly specified?
A public
B private
C protected
D internal
Correct Answer:  B. private
EXPLANATION

The default access modifier for class members in C# is 'private'. This means the member is only accessible within the same class unless explicitly specified otherwise.

Test
Q.10 Easy Basics & Syntax
In C#, which keyword is used to declare a variable that cannot be changed after initialization?
A const
B static
C readonly
D volatile
Correct Answer:  A. const
EXPLANATION

The 'const' keyword declares a constant whose value cannot be modified. Both 'const' and 'readonly' prevent changes, but 'const' is compile-time constant while 'readonly' is runtime constant.

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