Font size
WorksheetsElements of a C# program
Total questions: 40
Worksheet time: 28mins
What is the primary IDE recommended for C# development?
NetBeans
Eclipse
Visual Studio
IntelliJ IDEA
Which method in C# is used to print text followed by a newline?
Print()
Output()
WriteLine()
Write()
Which method allows printing without a newline in C#?
WriteLine()
PrintLine()
Write()
Output()
What is the correct syntax for declaring a variable in C#?
type variableName = value;
variableName = type value;
value = type variableName;
type = variableName value;
Which of the following is not a correct data type in C#?
int
float
number
string
What keyword is used to declare a constant variable?
var
let
final
const
What is the output of the following code? int x = 5; Console.WriteLine(x + 5);
5
10
15
20
Which operator is used for addition in C#?
&
+
%
*
How do you write a single-line comment in C#?
//
/*
#
--
Which type of casting is done automatically in C#?
Implicit Casting
Explicit Casting
Dynamic Casting
Static Casting
What does the const keyword do in C#?
Declares a variable that can be modified
Declares a variable that is constant and cannot be changed
Declares a global variable
Declares a temporary variable
Which of these is a logical operator in C#?
==
&&
++
+=
Which method is used to combine text and variables for output in C#?
Concat()
Merge()
+
Join()
What does the following code output? Console.WriteLine("Hello " + "World!");
Hello
Hello World!
HelloWorld!
Error
Which data type is used to store true or false values in C#?
int
boolean
float
string
Which keyword is used to convert data types explicitly in C#?
convert
ToString
casting
Convert
What does the == operator check in C#?
Whether two variables are equal
Whether a variable is less than another
Whether two variables are of the same type
None of the above
Which of the following is an arithmetic operator in C#?
&&
==
/
+=
What is the correct syntax for a multi-line comment in C#?
//
/*
#
What is the result of int a = 10; Console.WriteLine(a * 2);?
12
20
5
10
What is the size of the int data type in C#?
4 bytes
2 bytes
8 bytes
1 byte
Which function would you use to convert a double to int in C#?
int()
Convert.ToInt32()
Convert.ToDouble()
ToString()
What is the purpose of type casting in C#?
To change a variable's type at runtime
To assign a value of one type to another
To compare two variables
To join two strings
Which operator is used to compare two values in C#?
=
==
+=
&
Which is not a valid comparison operator in C#?
!=
>=
<=
==
Name the method used to output text in C# without a newline.
(a)
What is the keyword used to declare a constant variable in C#?
(a)
What is the symbol for single-line comments in C#?
(a)
Name the data type used to store textual data in C#.
(a)
Which operator is used for logical AND in C#?
(a)
What does IDE stand for?
(a)
Which method allows conversion of types, like Convert.ToInt32()
(a)
What is the output of a comparison operation?
(a)
What is the default value for an integer variable in C#?
(a)
What type of casting is for converting data from a smaller to a larger type?
(a)
What is the result of the expression 5 + 3 * 2 in C#?
(a)
What is the output of
int x = 10;
Console.WriteLine(x / 4);
(a)
What is the result of the modulus operation 17 % 5 in C#?
(a)
What is the value of
int x = 2;
int y = 2;
y++;
x--;
Console.Write(x+y-y*x);
(a)
What is the output of
Console.WriteLine(10.0 / 4);
(a)
