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 21–29 of 29
Topics in C# Programming
Q.21 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.22 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.23 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
Q.24 Easy Basics & Syntax
Which of the following is a value type in C#?
A String
B Enum
C Interface
D Delegate
Correct Answer:  B. Enum
EXPLANATION

Enum is a value type in C#. String, Interface, and Delegate are reference types.

Test
Q.25 Easy Basics & Syntax
What will be the output of the following code?
string s = "Hello";
s = s + " World";
Console.WriteLine(s);
A Hello
B Hello World
C Error
D World
Correct Answer:  B. Hello World
EXPLANATION

String concatenation using '+' operator joins the two strings. s becomes 'Hello World' after the concatenation.

Test
Q.26 Easy Basics & Syntax
Which of the following is NOT a valid C# variable name?
A _myVar
B my$Var
C myVar123
D MyVar
Correct Answer:  B. my$Var
EXPLANATION

Variable names in C# can contain letters, digits, and underscores. They cannot contain special characters like '$'. The variable name must start with a letter or underscore.

Test
Q.27 Easy Basics & Syntax
Which namespace is required to use Console.WriteLine() in C#?
A System.IO
B System
C System.Console
D System.Text
Correct Answer:  B. System
EXPLANATION

Console class is part of the System namespace. You need to include 'using System;' at the beginning of your code to use Console.WriteLine().

Test
Q.28 Easy Basics & Syntax
Which keyword is used to create a class in C#?
A class
B Class
C CLASS
D struct
Correct Answer:  A. class
EXPLANATION

C# is case-sensitive. The lowercase keyword 'class' is used to define a class. 'Class' and 'CLASS' are not valid keywords.

Test
Q.29 Easy Basics & Syntax
Which of the following is the correct syntax to declare a variable in C#?
A int x = 10;
B int x: 10;
C int x
D int x == 10;
Correct Answer:  A. int x = 10;
EXPLANATION

C# uses the syntax 'type variableName = value;' to declare and initialize variables. The equals sign (=) is the assignment operator.

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