Home Subjects C# Programming

C# Programming

C# and .NET for campus placement

76 Q 4 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 61–70 of 76
Topics in C# Programming
Q.61 Easy Basics & Syntax
What is the default access modifier for a class member in C# if not specified?
A public
B private
C protected
D internal
Correct Answer:  B. private
EXPLANATION

The default access modifier for class members is 'private'. For top-level classes, it's 'internal' by default.

Test
Q.62 Easy Basics & Syntax
In C#, which keyword is used to create a constant variable that cannot be modified after initialization?
A const
B static
C readonly
D immutable
Correct Answer:  A. const
EXPLANATION

The 'const' keyword creates a compile-time constant in C#. 'readonly' creates a runtime constant, 'static' defines class-level members, and 'immutable' is not a C# keyword.

Test
Q.63 Easy Basics & Syntax
What is the output of: decimal d = 10.5m; int x = (int)d; Console.WriteLine(x);
A 10.5
B 10
C 11
D compilation error
Correct Answer:  B. 10
EXPLANATION

Explicit casting from decimal to int truncates the decimal part, resulting in 10.

Test
Q.64 Easy Basics & Syntax
What will be the output of: int x = 10; int y = 20; int z = x > y ? x : y; Console.WriteLine(z);
A 10
B 20
C true
D false
Correct Answer:  B. 20
EXPLANATION

The ternary operator checks if x > y. Since 10 is not greater than 20, it returns y which is 20.

Test
Q.65 Easy Basics & Syntax
Which keyword is used to create a constant variable in C# that cannot be modified after initialization?
A constant
B const
C readonly
D static
Correct Answer:  B. const
EXPLANATION

The 'const' keyword creates a constant that must be initialized at declaration and cannot be changed. 'readonly' allows initialization in constructor.

Test
Q.66 Easy Basics & Syntax
What is the correct syntax for a multi-line comment in C#?
A -- comment here --
B // comment here
C /* comment here */
D # comment here
Correct Answer:  C. /* comment here */
EXPLANATION

/* */ is used for multi-line comments in C#. // is for single-line comments.

Test
Q.67 Easy Basics & Syntax
Which of the following is a reference type in C#?
A byte
B decimal
C class
D struct
Correct Answer:  C. class
EXPLANATION

Classes are reference types. byte, decimal are value types, and struct is also a value type.

Test
Q.68 Easy Basics & Syntax
What will be the output of: Console.WriteLine(10 / 3);
A 3.33
B 3
C 3.333333
D Compilation error
Correct Answer:  B. 3
EXPLANATION

Integer division in C# truncates the decimal part. 10 / 3 = 3 (not 3.33) because both operands are integers.

Test
Q.69 Easy Basics & Syntax
Which of the following correctly declares a variable that can hold null?
A int x = null;
B int? x = null;
C string x;
D object x = null;
Correct Answer:  B. int? x = null;
EXPLANATION

Only nullable types (using ?) can hold null values for value types. int? is a nullable integer that can hold null.

Test
Q.70 Easy Basics & Syntax
What is the default access modifier for a class member in C#?
A public
B private
C protected
D internal
Correct Answer:  B. private
EXPLANATION

The default access modifier for class members in C# is private, meaning they are accessible only within the same class.

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