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 11–20 of 29
Topics in C# Programming
Q.11 Easy Basics & Syntax
What will be printed when the following code executes?
string str = "Hello";
str = str + " World";
Console.WriteLine(str.Length);
A 5
B 11
C 6
D 10
Correct Answer:  B. 11
EXPLANATION

"Hello" has 5 characters. After concatenation with " World" (6 characters including space), the total length is 11.

Test
Q.12 Easy Basics & Syntax
In C#, what is the correct syntax to declare a nullable integer?
A int? number;
B int* number;
C nullable number;
D int[?] number;
Correct Answer:  A. int? number;
EXPLANATION

The '?' suffix is used to declare nullable value types in C#. int? means an integer that can also hold null values.

Test
Q.13 Easy Basics & Syntax
Which namespace must be included to use LINQ in C#?
A System.Collection
B System.Linq
C System.Data
D System.Threading
Correct Answer:  B. System.Linq
EXPLANATION

LINQ (Language Integrated Query) is available in the System.Linq namespace introduced in .NET 3.5.

Test
Q.14 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.15 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.16 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.17 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.18 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.19 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.20 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
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