1. Which of the following is NOT a primitive data type in C#?
a) int
b) double
c) string
d) bool
Explanation: string is not a primitive data type in C#; it is a reference type. Primitive data types include int, double, and bool.
2. What is the default access modifier for a class in C#?
a) public
b) private
c) internal
d) protected
Explanation: The default access modifier for a class in C# is internal, which means the class is accessible only within the same
assembly. For class members (fields, methods), the default is private.
3. Find the correctly initialized constructor:
a) obj1 = new obj();
b) obj1 = new ob;
c) obj1 = new object();
d) All of them are correct ways
4. Which is the right way of declaring an array?
a) int intArray[] = new int(5);
b) int[] intArray = new int[];
c) int[5] intArray = new int;
d) int[] intArray = new int[5];
Explanation: In C#, the correct way to declare an array is to specify the type followed by [], then assign it to a new array with
the size inside square brackets.
5. Which type or class does not have its own objects but acts in C#?
a) Abstract Class
b) Static Class
c) Sealed Class
d) Protected Class
6. Is overriding of a function possible in the same class in C#?
a) Yes
b) No
Explanation: Function overriding is not possible within the same class in C#. It is a feature that allows a derived class to provide a
specific implementation of a method defined in its base class.
7. Which array property is used to get the total number of elements?
a) Len
b) Length
Explanation: The Length property in C# is used to get the total number of elements in an array.
8. Which of the following is NOT a valid C# conditional operator?
a) >
b) <
c) ==
d) :=
Explanation: In C#, the operators >, <, and == are valid conditional operators. However, := is not a valid operator in C#; it is used
in some other programming languages like Pascal.
9. Which is the correct way to declare an object of the class in C#?
a) Class_Name Object_Name = new Class_Name();
b) Class_Name Object_Name = new Class_Name;
c) Class_Name Object_Name;
d) new Class_Name Object_Name = Class_Name();
Explanation: In C#, the correct syntax to declare and initialize an object is by using the new keyword followed by the class name
and parentheses. Option a) follows this syntax correctly.
10. static void Main(string[] args)
Console.WriteLine("Enter a number:");
int num = Console.ReadLine();
Console.WriteLine("Given number is: " + num);
a) Given number is: 123
b) Given number is:123
c) Given number is: 123
d) Error
Explanation: The code will throw an error because Console.ReadLine() returns a string, and it cannot be directly assigned to
an integer variable int num. The correct code should use int.Parse() or Convert.ToInt32() to convert the input string to an
integer, as shown below:
11. Which symbols are used to mark the beginning and end of a block in C#?
a) Square brackets []
b) Curly braces {}
c) Round brackets ()
d) Double quotes ""
Explanation: In C#, curly braces {} are used to define the beginning and end of a block of code, such as in methods, loops, or
conditional statements
12. What is the correct syntax to initialize a variable in C#?
a) type variableName = value;
b) type variableName;
c) variableName as type = value;
d) Both A and B
Explanation: The correct syntax to initialize a variable in C# is type variableName = value;. For example, int x = 10;. Option b)
type variableName; I s valid for declaring a variable without initializing it, but it doesn't meet the condition of initialization.
Option c) is not a valid C# syntax, and d) is incorrect since only a) meets the initialization requirement.
13. Which data type is used to store text values in C#?
a) text
b) txt
c) string
d) str
Explanation: In C#, the string data type is used to store text values. It is a reference type and is used to represent sequences of
characters. The other options (text, txt, str) are not valid data types in C#.
14. Which of the following is NOT a valid C# control flow statement?
a) if-else
b) switch
c) for
d) while-else
Explanation: In C#, there is no while-else statement. Valid control flow statements in C# include if-else, switch, for, while, and
do-while. The option while-else is not part of the C# syntax.
15.Which of the following is NOT a valid C# conditional operator?
a) >
b) <
c) ==
d) <>
Explanation: Explanation: The <> operator is not valid in C#. Instead, the inequality operator is written as !=. The operators >, <,
and == are all valid conditional operators in C#.
16. Which is the correct way to declare an object of the class in C#?
a) Class Name Object Name = new Class Name();
b) Class Name Object Name;
c) new Object Name as Class Name();
d) Both A and B
Explanation: In C#, you can declare an object of a class in two ways: a) Class Name Object Name = new Class Name(); initializes
the object at the time of declaration. b) Class Name Object Name; declares the object without initializing it. Initialization can be
done later. c) is not a valid syntax in C#.
17. What will be the output of the following C# code?
using System;
namespace MvApplication
{
class Program
static void Main(string[] args)
int a = 10, b = 20;
Console.WriteLine("{0} + {1}", a, b);
a) 20
b) 30
c) 10+20
d) 10+10
Explanation:
The Console.WriteLine("{0} + {1}", a, b) statement will print the values of a and b as a string, resulting in the output 10 + 20, not
the sum. It will display them as they are in the format string
18. What is 'Console' in C#?
a) Class
b) Object
c) Method
d) Structure
Explanation:
In C#, Console is a class provided by the System namespace. It is used for input and output operations, such as reading from and
writing to the console window.
19. C# programming language is used to develop-
a) Web apps
b) Desktop apps
c) Mobile apps
d) All of the above
Explanation:
C# is a versatile programming language used to develop various types of applications:
• Web apps: Through frameworks like ASP.NET.
• Desktop apps: Using Windows Forms, WPF, or UWP.
• Mobile apps: With Xamarin, a cross-platform mobile development framework.
20. What will be the output of the following C# code?
using System;
class Program {
static void Main(string[] args){
int i = 2;
int j = 10 % 4;
if(i == j) {
Console.WriteLine("True");
} else {
Console.WriteLine("False");
a) True
b) False
Explanation: i is assigned the value 2. j is assigned the value 10 % 4, which results in 2. Since i == j (both are 2), the condition is
true, and the output is "True".
21. In C#, a single-line comment starts with:
a) Two forward slashes (//)
b) Two backward slashes (\\)
c) A hash character (#)
d) A dollar character ($)
Explanation: In C#, a single-line comment begins with two forward slashes (//). Everything after these slashes on that line is
considered a comment.
22. Which of the following String methods is used to compare two strings?
a) CompareTo()
b) Concat()
c) Compare()
d) Copy()
Explanation: The CompareTo() method in C# is used to compare two strings. It returns an integer that indicates whether the first
string is less than, equal to, or greater than the second string.
23. The type 'float' can be safely converted to:
a) double
b) long
c) decimal
d) ufloat
Explanation: In C#, a float can be safely converted to a double because both float and double are floating-point types, but
double has higher precision. Conversion to decimal requires explicit casting, and long or ufloat are not valid conversions for
float.
24. Method parameters are enclosed in parentheses and a...
a) return type is specified
b) semicolon is used
c) method body is enclosed in curly braces
d) colon is used
25. Which C# keyword is used to come out from the loop?
a) break
b) continue
c) Both
d) none
Explanation: The break keyword is used in C# to exit or "break" out of a loop (like for, while, or foreach). The continue keyword,
on the other hand, is used to skip the current iteration of the loop and proceed to the next one.
26. In C#, the multi-line comments are placed within the ____?
a) /* */
b) // //
c) <!-- -->
d) """ """
Explanation: In C#, multi-line comments are enclosed between /* and */. Anything between these symbols is considered a
comment and is not executed. Single-line comments are created using //
27. What is the purpose of the foreach statement in C#?
a) To iterate over elements in collections or arrays
b) To sort elements in a collection
c) To check if a collection is empty
d) To modify elements in a collection
Explanation: The foreach statement in C# is used to iterate over each element in a collection or an array without the need for an
index variable. It is primarily used for reading data from collections. It does not modify the collection itself during iteration
28. To declare an array, define the variable type with ____?
a) []
b) {}
c) ()
d) none
Explanation: In C#, when declaring an array, the variable type is followed by square brackets []. For example: int[] arr; This
indicates that arr is an array of integers.
29. What is the correct syntax to define a C# constant?
a) const type constant_name
b) const type constant_name = value
c) const constant_name as type
d) const constant_name as type = value
Explanation: In C#, to define a constant, you use the const keyword followed by the type, the constant name, and the assigned
value. For example: const int number = 5;.
30. The type 'float' can be safely converted to:
a) double
b) long
c) decimal
d) ufloat
Explanation: In C#, a float can be safely converted to double because double has a larger range and higher precision. However,
float cannot be safely converted to long or decimal without explicit casting, and ufloat is not a valid C# type.
31. Method parameters are enclosed in parentheses and are separated by ____?
a) ;
b) ,
c) .
d)
Explanation: In C#, method parameters are enclosed in parentheses (), and multiple parameters are separated by commas. For
example: void Method(int x, string y)
32. Which keyword is used to define a constant in C#?
a) constant
b) const
c) static
d) readonly
Explanation: In C#, the const keyword is used to define a constant, which is a value that cannot be changed after it is assigned.
For example: const int maxValue = 100;
33. Is C# programming language case-sensitive?
a) Yes
b) No
Explanation: C# is a case-sensitive programming language, meaning that variable, Variable, and VARIABLE would be treated as
distinct identifiers.
34. Which of the following is the valid size of the float data type?
a) 4 byte
b) 6
c) 8
d) None
Explanation: In C#, the float data type occupies 4 bytes of memory. It represents a single-precision floating-point number.
35. What is the purpose of the this keyword in C#?
a) To refer to the current instance of a class
b) To create an instance of a class
c) To define a loop construct
d) To compare two variables
Explanation: The this keyword in C# is used to refer to the current instance of the class. It is commonly used to access instance
members (fields, properties, or methods) of the class from within its own methods or constructors.
36. _____ return the absolute value of a variable?
a) absolute[]
b) abs[]
c) absolutevariable[]
d) all
Explanation: In C#, the Math.Abs() method is used to return the absolute value of a variable. The correct option would be abs[],
although the proper syntax is Math.Abs(variable). The other options are not valid methods or keywords in C#
37. In C#, a namespace is the collection of classes?
a) True
b) False
Explanation: In C#, a namespace is used to group related classes, interfaces, structs, enums, and delegates together. It helps in
organizing code and avoiding name conflicts.
38. The protected access modifier defines a member that can be accessible:
a) Its class and all other classes
b) Its class and by derived class instances
c) Its class only
d) None of the above
Explanation: The protected access modifier allows access to a member from within its own class and any derived classes, but
not from other classes outside of the inheritance hierarchy.
39. What will be the output if the input is 123?
using System;
namespace MyApplication {
class Program {
static void Main(string[] args) {
Console.WriteLine("Enter a number");
int num = Console.ReadLine();
Console.WriteLine("Given number is " + num);
a) Given number is 123
b) Given number is "123"
c) Compile-time error
d) None of the above
Explanation: The code will result in a compile-time error because Console.ReadLine() returns a string, but the variable num is
declared as an int. To fix this, you would need to convert the input to an integer using int.Parse() or Convert.ToInt32(): int num
= Convert.ToInt32(Console.ReadLine());
40. How many times can a constructor be called during the lifetime of the object?
a) Only once
b) As many times as we call it
c) Any number of times before the object is deleted
d) None of the above
Explanation: A constructor in C# is called only once during the lifetime of an object. It is automatically invoked when the object
is created, and it cannot be called explicitly like a regular method.
41. What will be the output of the following code?
using System;
class Program {
static void Main(string[] args) {
int i = 100;
do {
Console.Write(i + " ");
++i;
} while (i <= 50);
}
a) Error
b) 100 101 102 ... infinite
c) 101
d) 100
42. What is the purpose of the this keyword in C#?
a) To refer to the current instance of a class
b) To create an instance of a class
c) To define a loop construct
d) To compare two variables