WorksheetsC# M-1
Total questions: 116
Worksheet time: 2hrs 56mins
CLR stands for ___________________
Common Language Runtime
Common Linguistic Runtime
Common Language Realtime
None of the above
When a program is compiled the code is converted into _________
Executable code
Objective code
MSIL
None
Is MSIL is platform dependant?
Yes
No
Identify the incorrect signature of Main() method.
void Main()
static void Main(string[] str)
static void Main(String[] args)
public static void Main()
Which of the following are the values types?
Int32
bool
double
class
Which of the following are the reference types?
Class
Delegate
String
All of the above
Struct in C# is _________________
Value type
Reference Type
Pointer
None of the above
Predict the output of the below code.
class Demo
{
static void Main()
{
Console.Write("Welcome to C#")
}
}
Would display, "Welcome to C#"
Compilation error at line number 3
Compilation error at line number 5
Code will compile but won't display anything
Who will identify the compilation errors in a aprogram?
CLR
Compiler
JIT
None of the above
Is Microsoft .NET a Open source framework
No
Yes
Which method converts the string representation of an integral to its Int32 representation?
parseInt()
ToInt()
parse()
None of the above
Which of the following is not a property of a string?
Strings are mutable
Strings are reference types
Strings have a default value null
Strings are immutable
In a visual studio project, can we have more than one entry point?
Yes
No
Which of the following are the reference types?
int
Delegate
String
Array
Is enum a reference type?
Yes
No
According to CTS all the types in .NET are derived from _________
System.Object
System.ValueType
System.Console
None of the above
The Read() method of Console class does __________
Reads collection of characters from the standard input stream
Reads a character from the standard input stream
Reads a character from the standard input stream till encounters a new like escape sequences
None of the above
The Read() method of Console class
returns collection of characters as string
returns a character
returns the ASCII value of a read character
None of the above
What is the output of the below statement.
int a=10;
int b=20;
Console.WriteLine("Sum is:"+a+b);
Sum is:30
Sum is:10+20
Sum is:1020
Gives compilation error
Does the .NET framework provide language compilers?
Yes
No
Which of the following is correct about variable naming conventions in C#?
Which of the following converts a type to a single Unicode character, where possible in C#?
SOAP stands for
simple object access program
simple object account program
simple object application program
simple object access protocol
CLR is the .NET equivalent of _________.
A. Java Virtual Machine
B. Common Language Runtime
C. Common Type System
D. Common Language Specification
The CLR is physically represented by an assembly named _______.
A. mscoree.dll
B. mcoree.dll
C. msoree.dll
D. mscor.dll
The ____ language allows more than one method in a single class.
A. C#
B. J#
C. C++
D. C
In C#, a subroutine is called a ________.
A. Function
B. Metadata
C. Method
D. Managed code
All C# applications begin execution by calling the _____ method.
A. Class()
B. Main()
C. Submain()
D. Namespace
A _______ is an identifier that denotes a storage location.
A. Constant
B. Reference type
C. Variable
D. Object
_________ are reserved, and cannot be used as identifiers.
A. Keywords
B. literal
C. variables
D. Identifiers
The character pair ?: is a________________available in C#.
A. Unary operator
B. Ternary operator
C. Decision operator
D. Functional operator
In C#, all binary operators are ______.
A. Center-associative
B. Right-associative
C. Left-associative
D. Top-associative
A _____ is any valid C# variable ending with a colon.
A. goto
B. Label
C. Logical
D. Bitwise
C# has _______ operator, useful for making two way decisions.
A. Looping
B. Functional
C. Exponential
D. Conditional
________causes the loop to continue with the next iteration after skipping any statements in between.
A. Loop
B. Exit
C. Break
D. Continue
Arrays in C# are ______ objects.
A. Reference
B. Logical
C. Value
D. Arithmetic
______ parameters are used to pass results back to the calling method.
A. Input
B. Reference
C. Value
D. Output
C# does not support _____ constructors.
A. parameterized
B. parameter-less
C. Class
D. Method
A structure in C# provides a unique way of packing together data of ______ types.
A. Different
B. Same
C. Invoking
D. Calling
The C# provides special methods known as _____ methods to provide access to data members.
A. Loop
B. Functions
C. Methods
D. Accessor
Inheritance is ______ in nature.
A. Commutative
B. Associative
C. Transitive
D. Iterative
In C#, having unreachable code is always an _____.
A. Method
B. Function
C. Error
D. Iterative
C# treats the multiple catch statements like cases in a _____________ statement.
A. If
B. Switch
C. For
D. While
A. If
B. Switch
C. For
D. While
C# supports a technique known as________, which allows a method to specify explicitly the name of the interface it is implementing.
A. Method Implementaion
B. Implicit Interface Implementation
C. Explicit Interface Implementation
D. Iterative Interface Implementation
The reason that C# does not support multiple inheritances is because of ______.
A. Method collision
B. Name collision
C. Function collision
D. Interface collision
2. C# runs on the ___.
.NET Framework
Java Virtual Machine
Both A. and B.
None of the above
5. What does the CLR in C# do?
Manages the execution of Webpages programs
Manages the parsing of the various types
Manages the execution of .NET programs
All of the above
9. What is 'Console' in C#?
Class
Object
Method
Structure
What will be the output of the following C# code?
static void Main(string[] args)
{
int a, b, c, x;
a = 80;
b = 15;
c = 2;
x = a - b / (3 c) ( a + c);
Console.WriteLine(x);
Console.ReadLine();
}
78
-84
80
98
What will be the output of the following C# code?
m = 5; int y;
y = m++;
y = ++m;
y = 5, m = 6; y = 7, m = 7
y = 6, m = 6; y = 7, m = 6
y = 5, m = 6 ; y = 5, m = 5
y = 5, m = 6; y = 7, m = 8
What will be the output of the following C# code?
bool a = true;
bool b = false;
a |= b;
Console.WriteLine(a);
Console.ReadLine();
0
1
True
False
What will be the output of the following C# code?
static void Main(string[] args)
{
int a = 5, b = 10;
if (Convert.ToBoolean(Convert.ToInt32(++a)) || Convert.ToBoolean(Convert.ToInt32(++b))) {
Console.WriteLine(a + "\n" + b);
}
else
Console.WriteLine(" C# ");
}
6 11
6 16
6 12
6 10
What will be the output of the following C# code?
static void Main(string[] args)
{
char ch = 'p';
switch (ch)
{
case 'p':
Console.WriteLine("coco" + "\t" + Convert.ToInt32(ch));
break;
default:
Console.WriteLine("default");
break;
}
Console.WriteLine("main");
}
coco main
coco 112
coco 112 main
compile time error
What will be the output of the following C# code?
static void Main(string[] args)
{
int i = 0;
if (i == 0)
{
goto label;
}
label: Console.WriteLine("HI...");
Console.ReadLine();
}
Hi…infinite times
Code runs prints nothing
Hi Hi
Hi…
Which of the following is used to define the member of a class externally?
:
::
#
none of the mentioned
What does the following C# code imply?
cs abc; abc = new cs();
Object creation on class csharp
Create an object of type csharp on heap or on stack depending on the size of object
create a reference c on csharp and an object of type csharp on heap
create an object of type csharp on stack
Which reference modifier is used to define a reference variable?
&
ref
#
$
Which of these can be overloaded?
Constructors
Methods
Both Constructors & Methods
None of the mentioned
Select the output for the following set of code:
1. static void Main(string[] args)
2. {
3. int y = 5;
4. int x;
5. int k = (!(Convert.ToInt32(y) > 10))? x = y + 3 : x = y + 10;
6. Console.WriteLine(x);
7. Console.WriteLine(y);
8. Console.ReadLine();
9. }
5, 8
8, 5
11, 8
10, 4
Give the Correct Output for the given set of programming code is :
1. class Program
2. {
3. static void Main(string[] args)
4. {
5. int i ;
6. for ( i = 0; i < 5; i++)
7. {
8. int j = 0;
9. j += i;
10. Console. WriteLine(j);
11. }
12. Console. WriteLine(i);
13. Console. ReadLine();
14. }
15. }
0, 1, 2, 3, 4, 5, 6
0, 1, 2, 3, 4
0, 1, 2, 3, 4, 5
0, 1, 2, 3
Select the output for the following set of Code :
1. static void Main(string[] args)
2. {
3. int a = -1;
4. int b = -1;
5. if (Convert.ToBoolean (++a = ++b))
6. Console.WriteLine("a");
7. else
8. Console.WriteLine("b");
9. Console.ReadLine();
10. }
a
b
Compile time error
Code execute successfully with no output
1. static void Main(string[] args)
2. {
3. int x;
4. x = Convert.ToInt32(Console.ReadLine());
5. int c = 1;
6. while (c <= x)
7. {
8. if (c % 2 == 0)
9. {
10. Console.WriteLine("Execute While " + c + "\t" + "time");
11. }
12. c++;
13. }
14. Console.ReadLine();
15. }
for x = 8 the program output will be,
Execute while 1 time Execute while 3 time Execute while 5 time Execute while 7 time
Execute while 2 time Execute while 4 time Execute while 6 time Execute while 8 time
Execute while 1 time Execute while 2 time Execute while 3 time Execute while 4 time Execute while 5 time Execute while 6 time Execute while 7 time
Execute while 2 time Execute while 3 time Execute while 4 time Execute while 5 time
Select the output for the following set of code :
1. static void Main(string[] args)
2. {
3. int i = 0;
4. int j = 0;
5. for (i = 0; i < 4; i++)
6. {
7. for (j = 0; j < 3; j++)
8. {
9. if (i > 1)
10. continue;
11. Console.WriteLine("Hi \n");
12. }
13. }
14. Console.ReadLine();
15. }
Prints hi 4 times
Prints hi 3 times
Prints hi 6 times
Prints hi infinite times
Select the output for the following set of code :
1. class sample
2. {
3. public int i;
4. public int j;
5. public void fun(int i, int j)
6. {
7. this.i = i;
8. this.j = j;
9. }
10. }
11. class Program
12. {
13. static void Main(string[] args)
14. {
15. sample s = new sample();
16. s.i = 1;
17. s.j = 2;
18. s.fun(s.i, s.j);
19. Console.WriteLine(s.i + " " + s.j);
20. Console.ReadLine();
21. }
22. }
Error while calling s.fun() due to inaccessible level
Error as ‘this’ reference would not be able to call ‘i’ and ‘j’
1 2
Runs successfully but prints nothing
Select the correct output for the following code
1. class z
2. {
3. public int X;
4. public int Y;
5. public const int c1 = 5;
6. public const int c2 = c1 * 25;
7. public void set(int a, int b)
8. {
9. X = a;
10. Y = b;
11. }
12.
13. }
14. class Program
15. {
16. static void Main(string[] args)
17. {
18. z s = new z();
19. s.set(10, 20);
20. Console.WriteLine(s.X + " " + s.Y);
21. Console.WriteLine(z.c1 + " " + z.c2);
22. Console.ReadLine();
23. }
24. }
10 20 5 25
20 10 25 5
10 20 5 125
20 10 125 5
The output of code is ?
1. class test
2. {
3. public void print()
4. {
5. Console.WriteLine("Csharp:");
6. }
7. }
8. class Program
9. {
10. static void Main(string[] args)
11. {
12. test t;
13. t.print();
14. Console.ReadLine();
15. }
16. }
Code runs successfully prints nothing
Code runs and prints “Csharp”
None of the mentioned
Syntax error as t is unassigned variable which is never used
What is output for the following set of code?
1. static void Main(string[] args)
2. {
3. string s1 = "Hello";
4. string s2 = "hello";
5. if (s1 == s2)
6. Console.WriteLine("Equal");
7. else
8. Console.WriteLine("Unequal");
9. if (s1.Equals (s2))
10. Console.WriteLine("Equal");
11. else
12. Console.WriteLine("Unequal");
13. Console.ReadLine();
14. }
Equal Unequal
compiler error
Equal Equal
Unequal Unequal
Which of the following statements are correct?
String is value type
String literals can contain any character literal including escape sequences
The equality operators are defined to compare values of string objects as well as references
All of the mentioned
What is output of the following set of code?
1. static void Main(string[] args)
2. {
3. Program p = new Program();
4. p.display(2, 3, 8);
5. int []a = { 2, 56, 78, 66 };
6. Console.WriteLine("example of array");
7. Console.WriteLine("elements added are");
8. p.display(a);
9. Console.ReadLine();
10. }
11. public void display(params int[] b)
12. {
13. foreach (int i in b)
14. {
15. Console.WriteLine("ARRAY IS HAVING:{0}", i);
16. }
17. }
Compile time error
Run time error
Code runs successfully but prints nothing
Code runs successfully and prints given on console
Choose selective differences between an array in c# and array in other programming languages.
Declaring array in C# the square bracket([]) comes after the type but not after identifier
It is necessary to declare size of an array with its type
No difference between declaration of array in c# as well as as in other programming languages
All of the mentioned
What will be the correct output for the given code snippet?
1. class recursion
2. {
3. int fact(int n)
4. {
5. int result;
6. if (n == 1)
7. return 1;
8. result = fact(n - 1) * n;
9. return result;
10. }
11. }
12. class Program
13. {
14. public static void main(String args[])
15. {
16. recursion obj = new recursion() ;
17. Console.WriteLine(obj.fact(4));
18. }
19. }
24
30
120
144
What will be the correct output the for the given code snippet?
1. class maths
2. {
3. int fact(int n)
4. {
5. int result;
6. if (n == 1)
7. return 1;
8. result = fact(n - 1) * n;
9. return result;
10. }
11. }
12. class Output
13. {
14. static void main(String args[])
15. {
16. maths obj = new maths() ;
17. Console.WriteLine(obj.fact(1));
18. }
19. }
2
10
1
0
What will be the correct output for the given code snippet?
1. class maths
2. {
3. int fact(int n)
4. {
5. int result;
6. if (n == 1)
7. return 1;
8. result = fact(n - 1) n;
9. return result;
10. }
11. }
12. class Output 1
3. {
14. static void main(String args[])
15. {
16. maths obj = new maths() ;
17. Console.WriteLine(obj.fact(4)obj.fact(2));
18. }
19. }
64
60
120
48
What are the main types of inheritance in C#?
Single Inheritance, Multiple Inheritance (through interfaces), Multilevel Inheritance, Hierarchical Inheritance
Circular Inheritance
Abstract Inheritance
Static Inheritance
Explain single inheritance and its advantages.
Single inheritance is only applicable in functional programming languages.
Single inheritance can lead to code duplication in large projects.
Multiple inheritance allows for more complex relationships between classes.
Advantages of single inheritance include simplicity in the class hierarchy, easier maintenance, reduced complexity, and improved code reusability.
What is multiple inheritance and how is it achieved in C#?
Multiple inheritance is achieved through abstract classes in C#.
C# does not support multiple inheritance at all.
A class can inherit from multiple base classes directly in C#.
In C#, multiple inheritance is achieved through interfaces, allowing a class to implement multiple interfaces.
Define method overriding in the context of C# inheritance.
Method overriding allows a base class to change its own methods.
Method overriding is used to create new methods in the base class.
Method overriding prevents derived classes from accessing base class methods.
Method overriding in C# allows a derived class to provide a specific implementation of a method that is already defined in its base class.
How does the 'virtual' keyword affect method overriding?
The 'virtual' keyword prevents method overriding in derived classes.
The 'virtual' keyword has no effect on method overriding.
The 'virtual' keyword enables polymorphism and allows derived classes to override base class methods.
The 'virtual' keyword is used to declare static methods only.
What is an abstract class and how is it used in C#?
An abstract class in C# can be instantiated directly.
An abstract class in C# is used to create concrete classes only.
An abstract class in C# is a class that cannot be instantiated and is used to define a base class with abstract methods for derived classes to implement.
An abstract class in C# cannot contain any methods or properties.
Can an abstract class have concrete methods?
An abstract class can only have static methods.
Yes, all methods in an abstract class must be abstract.
Yes, an abstract class can have concrete methods.
No, an abstract class cannot have any methods.
What is the purpose of an interface in C#?
To provide a way to inherit implementation details.
To create a new data type with properties.
To define a contract for classes to implement.
To manage memory allocation for classes.
How do interfaces differ from abstract classes?
Interfaces allow multiple inheritance and only contain method signatures; abstract classes can provide implementation and cannot be instantiated.
Abstract classes allow multiple inheritance and only contain method signatures.
Interfaces cannot be inherited by multiple classes.
Interfaces can be instantiated and contain method implementations.
What is polymorphism and how does it relate to inheritance?
Polymorphism is a type of inheritance that only applies to abstract classes.
Polymorphism allows different classes to be treated as instances of the same class through inheritance, enabling method overriding and dynamic behavior.
Polymorphism is unrelated to inheritance and focuses solely on data encapsulation.
Polymorphism restricts classes to a single method implementation.
Explain the concept of compile-time polymorphism in C#.
Compile-time polymorphism cannot be implemented in C# using interfaces.
Compile-time polymorphism is a runtime feature in C#.
Compile-time polymorphism is only achieved through inheritance.
Compile-time polymorphism in C# is achieved through method overloading and operator overloading.
What is runtime polymorphism and how is it achieved in C#?
Runtime polymorphism is achieved in C# through method overriding using virtual and override keywords.
Runtime polymorphism is achieved by using static methods in C#.
Runtime polymorphism is achieved through method overloading using the new keyword.
Runtime polymorphism is implemented using interfaces and abstract classes only.
How can you implement an interface in a class?
Use the 'implements' keyword in the class declaration and define all interface methods.
Use the 'override' keyword to implement interface methods.
Define interface methods without implementing them.
Use the 'extends' keyword in the class declaration.
What happens if a class does not implement all members of an interface?
The class will automatically implement the missing members.
The class will not compile.
The class will run but produce runtime errors.
The class will inherit the members from a parent class.
Can a class inherit from multiple interfaces?
No, a class can only inherit from one interface.
No, interfaces cannot be inherited by classes.
Yes, but only if the interfaces are related.
Yes, a class can inherit from multiple interfaces.
What will be the output of the following C# code?
static void Main(string[] args)
{
int a, b, c, x;
a = 80;
b = 15;
c = 2;
x = a - b / (3 c) ( a + c);
Console.WriteLine(x);
Console.ReadLine();
}
78
-84
80
98
What will be the output of the following C# code?
m = 5; int y;
y = m++;
y = ++m;
y = 5, m = 6; y = 7, m = 7
y = 6, m = 6; y = 7, m = 6
y = 5, m = 6 ; y = 5, m = 5
y = 5, m = 6; y = 7, m = 8
What will be the output of the following C# code?
bool a = true;
bool b = false;
a |= b;
Console.WriteLine(a);
Console.ReadLine();
0
1
True
False
What will be the output of the following C# code?
static void Main(string[] args)
{
int a = 5, b = 10;
if (Convert.ToBoolean(Convert.ToInt32(++a)) || Convert.ToBoolean(Convert.ToInt32(++b))) {
Console.WriteLine(a + "\n" + b);
}
else
Console.WriteLine(" C# ");
}
6 11
6 16
6 12
6 10
What will be the output of the following C# code?
static void Main(string[] args)
{
char ch = 'p';
switch (ch)
{
case 'p':
Console.WriteLine("coco" + "\t" + Convert.ToInt32(ch));
break;
default:
Console.WriteLine("default");
break;
}
Console.WriteLine("main");
}
coco main
coco 112
coco 112 main
compile time error
What will be the output of the following C# code?
static void Main(string[] args)
{
int i = 0;
if (i == 0)
{
goto label;
}
label: Console.WriteLine("HI...");
Console.ReadLine();
}
Hi…infinite times
Code runs prints nothing
Hi Hi
Hi…
Which of the following is used to define the member of a class externally?
:
::
#
none of the mentioned
What does the following C# code imply?
cs abc; abc = new cs();
Object creation on class csharp
Create an object of type csharp on heap or on stack depending on the size of object
create a reference c on csharp and an object of type csharp on heap
create an object of type csharp on stack
Which reference modifier is used to define a reference variable?
&
ref
#
$
Which of these can be overloaded?
Constructors
Methods
Both Constructors & Methods
None of the mentioned
What is the syntax to declare a variable in C#?
myVariable = int;
int myVariable;
var myVariable;
myVariable = int;
Which data type is used to store whole numbers in C#?
boolean
float
string
int
What is the purpose of control structures in C#?
The purpose of control structures in C# is to randomly change the output of a program.
The purpose of control structures in C# is to slow down the execution of a program.
The purpose of control structures in C# is to add unnecessary complexity to the code.
The purpose of control structures in C# is to control the flow of execution in a program.
Which control structure is used to execute a block of code repeatedly?
if-else
switch
for loop
loop
What is an array in C#?
A data structure that stores a variable-size sequence of elements of different types.
A data structure that stores a fixed-size sequence of elements of the same type.
A programming language used for web development.
A function that performs a specific task in C#.
How do you access elements in an array in C#?
myArray[index]
myArray{index}
myArray(index)
myArray.index
What is object-oriented programming (OOP) in C#?
Object-oriented programming (OOP) in C# is a programming technique used for writing efficient algorithms.
Object-oriented programming (OOP) in C# is a programming language used for creating graphical user interfaces.
Object-oriented programming (OOP) in C# is a programming paradigm that allows for the creation of objects that contain both data and methods.
Object-oriented programming (OOP) in C# is a programming concept that focuses on procedural programming.
What are the four pillars of OOP in C#?
encapsulation, inheritance, polymorphism, and encapsulation
encapsulation, inheritance, polymorphism, and abstraction
encapsulation, inheritance, polymorphism, and encapsulation
encapsulation, inheritance, polymorphism, and encapsulation
What is exception handling in C#?
Exception handling in C# is a way to ignore runtime errors and continue program execution.
Exception handling in C# is a feature that allows the programmer to intentionally introduce errors in the program.
Exception handling in C# is a technique to prevent runtime errors from occurring in a program.
Exception handling in C# is a mechanism to handle runtime errors or exceptions that occur during the execution of a program.
How do you handle exceptions in C#?
Using try-catch blocks
Using switch statements
Using for loops
Using if-else statements
a
b
c
d
a
b
c
d
a
b
c
d
a
b
c
d
a
b
c
d
a
b
c
d
a
b
c
d
a
b
c
d
