# C# Programming Language Practice Test

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
| By D_mahalakshmi
D
D_mahalakshmi
Community Contributor
Quizzes Created: 1 | Total Attempts: 263
Questions: 35 | Attempts: 263

Settings

• 1.

### 1.     If “real” data type is used in Database, whats  the equivalent datatype in C#-

• A.

Decimal

• B.

Single

• C.

Double

• D.

None

B. Single
Explanation
The equivalent data type in C# for the "real" data type used in a database is "Single".

Rate this question:

• 2.

### 1.     String a= “100”; int b = 10; ___________ What should be written to get the out put as 110?

• A.

A.Int c = a+b;

• B.

B.String c = a + b;

• C.

C.Int c = Convert.ToInt32(a) + b;

• D.

D.Int c = Convert.ToInt32(a+b);

C. C.Int c = Convert.ToInt32(a) + b;
Explanation
To get the output as 110, the string variable "a" needs to be converted to an integer. This can be done using the Convert.ToInt32() method. Then, the integer variable "b" can be added to the converted integer value of "a" and stored in the integer variable "c". Therefore, the correct answer is c.Int c = Convert.ToInt32(a) + b.

Rate this question:

• 3.

### 1.     Array is a abstract class. So It cannot have constructor---

• A.

A.True

• B.

B.False

A. A.True
Explanation
The statement is true because an abstract class cannot be instantiated, meaning that objects of an abstract class cannot be created. Since a constructor is used to create objects, it is not allowed in an abstract class. Therefore, the given statement correctly states that an array, being an abstract class, cannot have a constructor.

Rate this question:

• 4.

### 1.  Can an Interface be instantiated directly?

• A.

A.Yes

• B.

B.No

• C.

C.It can be instantiated with static constructor

• D.

D.None of these

B. B.No
Explanation
An interface cannot be instantiated directly because it is an abstract type that only defines the structure and behavior of a class. It cannot be used to create objects on its own. Instead, it is implemented by classes, which provide the necessary functionality. Therefore, the correct answer is "No."

Rate this question:

• 5.

### 1. What is the Difference between Convert.ToInt32 and Int.Parse?

• A.

A.Both are Same

• B.

B.Int.Parse Can't Handle Null values , It will throws ArgumentNull Exception Error.

• C.

C.Convert.ToInt32 Can't Handle Null Values ,it will throws ArgumentNullException error.

• D.

D.Both can Handle Null Values

• E.

E.Both can't Handle Null Values

B. B.Int.Parse Can't Handle Null values , It will throws ArgumentNull Exception Error.
Explanation
Int.Parse and Convert.ToInt32 are both methods used to convert a string to an integer in C#. However, there is a difference between the two. Int.Parse cannot handle null values and will throw an ArgumentNullException error if it encounters a null value. On the other hand, Convert.ToInt32 can handle null values and will not throw an error in such cases. Therefore, the correct answer is b.Int.Parse Can't Handle Null values, It will throw an ArgumentNullException error.

Rate this question:

• 6.

### 1. What is the difference between Convert.ToString(str) and str.ToString() method?

• A.

A.Convert.ToString(str) function handles NULL while str.ToString() does not. It will throw a NULL reference exception.

• B.

B.str.ToString() function handles NULL while Convert.ToString(str) does not. It will throw a NULL reference exception.

• C.

C.Both can handle NULL

• D.

D.None can Handle NULL

A. A.Convert.ToString(str) function handles NULL while str.ToString() does not. It will throw a NULL reference exception.
Explanation
The correct answer is a. Convert.ToString(str) function handles NULL while str.ToString() does not. It will throw a NULL reference exception. This means that if the variable "str" is null, using Convert.ToString(str) will return an empty string instead of throwing an exception, while using str.ToString() will throw a NULL reference exception.

Rate this question:

• 7.

### 1. Which of the following statements are correct about the Bitwise & operator used in C#.NET?

• A.

The & operator can be used to Invert a bit.

• B.

The & operator can be used to put ON a bit.

• C.

The & operator can be used to put OFF a bit.

• D.

The & operator can be used to check whether a bit is ON.

• E.

The & operator can be used to check whether a bit is OFF.

C. The & operator can be used to put OFF a bit.
D. The & operator can be used to check whether a bit is ON.
E. The & operator can be used to check whether a bit is OFF.
Explanation
The bitwise & operator in C#.NET can be used to put OFF a bit by performing a bitwise AND operation between two numbers, where the result will have the corresponding bit turned off if both bits are turned on. Additionally, the & operator can be used to check whether a bit is ON by performing a bitwise AND operation between the number and a mask where the bit of interest is turned on. If the result is not zero, it means the bit is ON. Similarly, the & operator can also be used to check whether a bit is OFF by performing a bitwise AND operation between the number and a mask where the bit of interest is turned off. If the result is zero, it means the bit is OFF.

Rate this question:

• 8.

### 1. Which of the following statements are correct?

• A.

The conditional operator (?:) returns one of two values depending on the value of a Boolean expression.

• B.

The &* operator is also used to declare pointer types and to dereference pointers.

• C.

In addition to being used to specify the order of operations in an expression, brackets [ ] are used to specify casts or type conversions.

A. The conditional operator (?:) returns one of two values depending on the value of a Boolean expression.
Explanation
The conditional operator (?:) returns one of two values depending on the value of a Boolean expression. This operator is commonly used as a shorthand for an if-else statement. It evaluates the Boolean expression and if it is true, it returns the value before the colon (:), otherwise it returns the value after the colon. This allows for concise and efficient code when making decisions based on a condition.

Rate this question:

• 9.

### 1. Which of the following is an 8-byte Integer?

• A.

Char

• B.

Long

• C.

Short

• D.

Byte

• E.

Integer

B. Long
Explanation
The correct answer is "Long" because a Long data type in Java is an 8-byte integer. It can store values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Other options such as Char, Short, Byte, and Integer have smaller storage sizes and cannot hold values as large as an 8-byte integer.

Rate this question:

• 10.

### 1. What is the size of a Decimal?

• A.

4 byte

• B.

8 byte

• C.

16 byte

• D.

32 byte

C. 16 byte
Explanation
The size of a Decimal is 16 bytes. This data type is used to store decimal numbers with high precision and is commonly used in financial and monetary calculations. The 16-byte size allows for a larger range of values and more precise calculations compared to other numeric data types.

Rate this question:

• 11.

### 1. Which of the following statements are correct?  (Choose 2)

• A.

We can assign values of any type to variables of type object.

• B.

When a variable of a value type is converted to object, it is said to be unboxed.

• C.

When a variable of type object is converted to a value type, it is said to be boxed.

• D.

Boolean variable cannot have a value of null.

• E.

When a value type is boxed, an entirely new object must be allocated and constructed.

A. We can assign values of any type to variables of type object.
E. When a value type is boxed, an entirely new object must be allocated and constructed.
Explanation
The correct answer is that we can assign values of any type to variables of type object and when a value type is boxed, an entirely new object must be allocated and constructed. This means that objects of any type can be stored in variables of type object, and when a value type is converted to object, it is boxed and a new object is created to hold the value.

Rate this question:

• 12.

### 1. Which of the following statements are correct about data types?  (Choose 3)

• A.

Each value type has an implicit default constructor that initializes the default value of that type.

• B.

It is possible for a value type to contain the null value.

• C.

All value types are derived implicitly from System.ValueType class.

• D.

It is not essential that local variables in C# must be initialized before being used.

• E.

Variables of reference types referred to as objects and store references to the actual data.

A. Each value type has an implicit default constructor that initializes the default value of that type.
C. All value types are derived implicitly from System.ValueType class.
E. Variables of reference types referred to as objects and store references to the actual data.
Explanation
The first statement is correct because each value type in C# has an implicit default constructor that initializes the default value of that type. The second statement is incorrect because value types cannot contain the null value, only reference types can. The third statement is correct because all value types in C# are derived implicitly from the System.ValueType class. The fourth statement is incorrect because in C#, local variables must be initialized before being used. The fifth statement is correct because variables of reference types are referred to as objects and they store references to the actual data.

Rate this question:

• 13.

### 1. Which of the following statements are TRUE about the .NET CLR?        (Choose which ever is correct)

• A.

It provides a language-neutral development & execution environment.

• B.

It ensures that an application would not be able to access memory that it is not authorized to access.

• C.

It provides services to run "managed" applications

• D.

The resources are garbage collected.

• E.

It provides services to run "unmanaged" applications.

A. It provides a language-neutral development & execution environment.
B. It ensures that an application would not be able to access memory that it is not authorized to access.
C. It provides services to run "managed" applications
D. The resources are garbage collected.
Explanation
The correct answer is that the .NET CLR provides a language-neutral development & execution environment, ensures that an application would not be able to access memory that it is not authorized to access, provides services to run "managed" applications, and the resources are garbage collected. This means that the CLR allows developers to write code in multiple languages, enforces memory access restrictions, supports running applications that are managed by the CLR, and automatically frees up memory by garbage collecting unused resources.

Rate this question:

• 14.

### 1. Which of the following components of the .NET framework provide an extensible set of classes that can be used by any .NET compliant programming language?

• A.

.NET class libraries

• B.

Common Language Runtime

• C.

Common Language Infrastructure

• D.

Component Object Model

• E.

Common Type System

A. .NET class libraries
Explanation
The .NET class libraries provide an extensible set of classes that can be used by any .NET compliant programming language. These libraries contain pre-built code that developers can use to perform common tasks, such as file input/output, database access, and networking. By using the .NET class libraries, developers can save time and effort by leveraging existing code rather than writing everything from scratch. Additionally, the .NET class libraries are designed to be language-agnostic, meaning that they can be used with any programming language that is compatible with the .NET framework.

Rate this question:

• 15.

### 1. Which of the following jobs are done by Common Language Runtime?

• A.

It provides core services such as memory management, thread management, and remoting.

• B.

It enforces strict type safety.

• C.

It provides Code Access Security

• D.

It provides Garbage Collection Services

• E.

All the above

E. All the above
Explanation
The Common Language Runtime (CLR) is responsible for providing core services such as memory management, thread management, and remoting. It also enforces strict type safety to ensure that code is executed securely. Additionally, the CLR provides Code Access Security to protect against unauthorized access to system resources. Lastly, it provides Garbage Collection Services to automatically manage memory and deallocate objects that are no longer in use. Therefore, all of the given options are jobs done by the Common Language Runtime.

Rate this question:

• 16.

### 1. Which of the following statements are correct about functions used in C#.NET?  (Choose 3)

• A.

Function definitions cannot be nested.

• B.

Functions can be called recursively.

• C.

If we do not return a value from a function then a value -1 gets returned.

• D.

To return the control from middle of a function exit function should be used.

• E.

Function calls can be nested.

A. Function definitions cannot be nested.
B. Functions can be called recursively.
E. Function calls can be nested.
Explanation
The first statement is correct because function definitions cannot be nested in C#.NET. This means that you cannot define a function inside another function.

The second statement is correct because functions can be called recursively in C#.NET. This means that a function can call itself during its execution.

The fifth statement is correct because function calls can be nested in C#.NET. This means that a function can be called from within another function, creating a nested call structure.

Rate this question:

• 17.

### 1. How many values is a function capable of returning?

• A.

1

• B.

0

• C.

Depends upon how many params arguments does it use.

• D.

Any number of values

• E.

Depends upon how many ref arguments does it use.

A. 1
Explanation
A function is capable of returning only one value.

Rate this question:

• 18.

### 1. Which of the following statements are correct?

• A.

Instance members of a class can be accessed only through an object of that class.

• B.

A class can contain only instance data and instance member function.

• C.

All objects created from a class will occupy equal number of bytes in memory.

• D.

A class can contain Friend functions.

• E.

A class is a blueprint or a template according to which objects are created.

A. Instance members of a class can be accessed only through an object of that class.
C. All objects created from a class will occupy equal number of bytes in memory.
E. A class is a blueprint or a template according to which objects are created.
Explanation
The first statement is correct because instance members of a class can only be accessed through an object of that class. The second statement is incorrect because a class can also contain static data and static member functions. The third statement is incorrect because objects created from a class can occupy different number of bytes in memory depending on their data members and the compiler's implementation. The fourth statement is correct because a class can contain Friend functions. The fifth statement is correct because a class is indeed a blueprint or template according to which objects are created.

Rate this question:

• 19.

### 1. Which of the following is the incorrect form of Decision Control instruction?

• A.

If (Condition1) {// Some statement}

• B.

If (Condition1) {// Some statement} else {// Some statement}

• C.

If (Condition1) {// Some statement} else {// Some statement} else if ( Condition2){//Some statement}

• D.

If ( Condition1 ) {// Some statement} else if ( Condition2 ) {// Some statement} else {// Some statement}

• E.

If ( Condition1 ) {// Some statement} else if ( Condition2 ) {// Some statement} else if ( Condition3 ) {// Some statement} else {// Some statement}

C. If (Condition1) {// Some statement} else {// Some statement} else if ( Condition2){//Some statement}
Explanation
The given code snippet is the incorrect form of a decision control instruction because it contains two "else" statements consecutively. In a valid decision control structure, there can only be one "else" statement following an "if" statement. The correct form would be to use "else if" for subsequent conditions.

Rate this question:

• 20.

### 1. Which of the following statements are correct about the C#.NET code snippet given below? (Choose 3)   if (age > 18 && no < 11)     a = 25;

• A.

The condition no < 11 will be evaluated only if age > 18 evaluates to True.

• B.

The statement a = 25 will get executed if any one condition is True

• C.

The condition no < 11 will be evaluated only if age > 18 evaluates to False

• D.

The statement a = 25 will get executed if both the conditions are True.

• E.

&& is known as a short circuiting logical operator.

A. The condition no < 11 will be evaluated only if age > 18 evaluates to True.
D. The statement a = 25 will get executed if both the conditions are True.
E. && is known as a short circuiting logical operator.
Explanation
The given code snippet contains an if statement with two conditions, age > 18 and no < 11. The first correct statement explains that the condition no < 11 will only be evaluated if age > 18 is true. This is because the && operator is a short-circuiting logical operator, which means that if the first condition is false, the second condition will not be evaluated. The second correct statement states that the statement a = 25 will be executed if both conditions are true. Therefore, if age is greater than 18 and no is less than 11, the statement a = 25 will be executed.

Rate this question:

• 21.

### 1. Which of the following can be facilitated by the Inheritance mechanism? (Choose 3)

• A.

Use the existing functionality of base class.

• B.

Overrride the existing functionality of base class.

• C.

Implement new functionality in the derived class.

• D.

Implement polymorphic behaviour.

• E.

Implement containership.

A. Use the existing functionality of base class.
B. Overrride the existing functionality of base class.
C. Implement new functionality in the derived class.
Explanation
The Inheritance mechanism allows for the use of existing functionality of a base class, which means that the derived class can inherit and utilize the methods and attributes of the base class. It also allows for the override of existing functionality of the base class, meaning that the derived class can modify or replace the methods or attributes inherited from the base class. Additionally, the Inheritance mechanism enables the implementation of new functionality in the derived class, allowing for the addition of new methods or attributes specific to the derived class.

Rate this question:

• 22.

### 1. In an inheritance chain which of the following members of base class are accessible to the derived class members? (Chhose 2)

• A.

Static

• B.

Protected

• C.

Private

• D.

Shared

• E.

Public

B. Protected
E. Public
Explanation
In an inheritance chain, the protected members of the base class are accessible to the derived class members. Protected members can be accessed by the derived class as if they were its own members. Additionally, the public members of the base class are also accessible to the derived class members. Public members can be accessed by any class, including the derived class.

Rate this question:

• 23.

### 1. Which of the following will be the correct output for the C#.NET code snippet given below?   String s1 = "ALL MEN ARE CREATED EQUAL"; String s2; s2 = s1.Substring(12, 3);  Console.WriteLine(s2);

• A.

ARE

• B.

CRE

• C.

CR

• D.

REA

• E.

CREATED

B. CRE
Explanation
The code snippet is using the Substring method in C#.NET to extract a portion of the string "ALL MEN ARE CREATED EQUAL". The method takes two parameters: the starting index and the length of the substring to be extracted. In this case, the starting index is 12 and the length is 3. So, the substring that will be extracted is "CRE". Therefore, the correct output for the code snippet is "CRE".

Rate this question:

• 24.

### 1. Which of the following statements will correctly copy the contents of one string into another ?

• A.

String s1 = "String"; String s2; s2 = s1;

• B.

String s1 = "String" ; String s2; s2 = String.Concat(s1, s2);

• C.

String s1 = "String"; String s2; s2 = String.Copy(s1);

• D.

String s1 = "String"; String s2; s2 = s1.Replace();

• E.

String s1 = "String"; String s2; s2 = s2.StringCopy(s1);

C. String s1 = "String"; String s2; s2 = String.Copy(s1);
Explanation
The correct answer is "String s1 = "String"; String s2; s2 = String.Copy(s1);" because it uses the String.Copy() method to copy the contents of one string into another. This method creates a new string object with the same value as the original string.

Rate this question:

• 25.

### 1. which of the following statements are true about finally block?  (Choose 3)

• A.

Finally block is executed even if an error occurs

• B.

Finally block is definitely executed when leaving a try block.

• C.

Finally block is used to perform any necessary clean-up jobs.

• D.

Finally block is not executed if an error occurs

A. Finally block is executed even if an error occurs
B. Finally block is definitely executed when leaving a try block.
C. Finally block is used to perform any necessary clean-up jobs.
Explanation
The finally block is executed even if an error occurs, ensuring that any necessary clean-up jobs are performed. It is also definitely executed when leaving a try block, regardless of whether an error occurred or not.

Rate this question:

• 26.

### 1. System Exceptions are handled by

• A.

CTS

• B.

CLR

• C.

CLS

• D.

CSS

B. CLR
Explanation
System Exceptions are handled by CLR (Common Language Runtime). CLR is the runtime environment provided by the .NET framework that manages the execution of .NET programs. It is responsible for various tasks such as memory management, security, exception handling, and garbage collection. When a system exception occurs in a .NET program, CLR takes control and handles the exception by either terminating the program or providing appropriate error handling mechanisms. CLR ensures that the program's execution is managed in a safe and controlled manner, making it the correct answer for this question.

Rate this question:

• 27.

### 1. Is it possible to store multiple datatypes in System.Array

• A.

Possible

• B.

ImPossible

• C.

System.array can be listed

• D.

System.arrayList can be used

B. ImPossible
Explanation
It is not possible to store multiple datatypes in System.Array. System.Array is a fixed-size collection that can only store elements of a single datatype. If we need to store multiple datatypes, we can use System.Collections.ArrayList which allows storing elements of different datatypes.

Rate this question:

• 28.

### 1. Int I =0; For(;i<10;) {//loop 1 I++; For(;i>9;i--) { //loop2 } } How many times loop gets executed?

• A.

Infinite

• B.

1

• C.

2

• D.

0

• E.

None of these

A. Infinite
Explanation
The loop will execute infinitely because the condition for the first loop (i < 10) will always be true since i is initialized as 0 and incremented within the loop. Therefore, the loop will never terminate and continue executing indefinitely.

Rate this question:

• 29.

• A.

True

• B.

False

A. True
Explanation
Statement 1 and Statement 2 are not the same.

In Statement 1, the correct syntax is `Console.ReadLine("text");` where "text" is the prompt that will be displayed to the user. This method reads the input from the user as a string.

In Statement 2, `Console.In.Readline("text");` is not a valid syntax. The correct syntax is `Console.ReadLine();` without any arguments. This method also reads the input from the user as a string.

Therefore, the correct answer is False, as Statement 1 and Statement 2 are not the same.

Rate this question:

• 30.

### 1. Array is a abstract class. So It cannot have constructor---

• A.

True

• B.

False

A. True
Explanation
The statement is true because an abstract class cannot be instantiated, which means it cannot have a constructor. Abstract classes are meant to be extended by other classes, and their constructors are called when an instance of a subclass is created. Therefore, an abstract class itself does not need a constructor.

Rate this question:

• 31.

### 1. Which of the following statements is correct about the C#.NET code snippet given below?   int a = 10;  int b = 20;  int c = 30; enum color: byte {     red = a,      green = b,     blue = c    }

• A.

Variables cannot be assigned to enum elements.

• B.

Variables can be assigned to any one of the enum elements.

• C.

Variables can be assigned only to the first enum element.

• D.

Values assigned to enum elements must always be successive values.

• E.

Values assigned to enum elements must always begin with 0.

A. Variables cannot be assigned to enum elements.
Explanation
The given code snippet is defining an enum named "color" with three elements: red, green, and blue. The values of these elements are assigned using variables a, b, and c, which is not allowed in C#. Enum elements must have constant values, so variables cannot be assigned to enum elements.

Rate this question:

• 32.

### 1. Which of the following can be declared in an interface?  (Choose 3)

• A.

Properties

• B.

Methods

• C.

Enumerations

• D.

Events

• E.

Structures

A. Properties
B. Methods
D. Events
Explanation
In an interface, you can declare properties, methods, and events. An interface is a contract that defines a set of members that a class must implement. Properties allow you to define the characteristics or attributes of an object. Methods define the behavior or actions that an object can perform. Events allow objects to communicate with each other by sending and receiving notifications. Enumerations, structures, and other types of members cannot be declared in an interface.

Rate this question:

• 33.

### 1. What are the types of parameters?

• A.

Out

• B.

Ref

• C.

Params

• D.

Value

• E.

All the above

E. All the above
Explanation
The correct answer is "All the above" because all the mentioned options (out, ref, params, value) are types of parameters in programming. "out" parameters are used to pass data out of a method, "ref" parameters are used to pass data by reference, "params" parameters allow a variable number of arguments to be passed to a method, and "value" parameters are used to pass data by value. Therefore, all of these options are valid types of parameters.

Rate this question:

• 34.

### 1. Write the keyword which can be used to declare parameter arrays?

• A.

Params

• B.

Parra90

• C.

Parameter

A. Params
Explanation
The keyword "Params" can be used to declare parameter arrays.

Rate this question:

• 35.

### 1. Which one of the modifiers declare a method to be class method?

• A.

Private

• B.

Public

• C.

Static

• D.

Virtual

• E.

All the above

C. Static
Explanation
The correct answer is "static". In Java, the "static" modifier is used to declare a method as a class method. Class methods are associated with the class itself rather than with any specific instance of the class. They can be called directly on the class without creating an object of the class.

Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

• Current Version
• Mar 18, 2023
Quiz Edited by
ProProfs Editorial Team
• Dec 27, 2011
Quiz Created by
D_mahalakshmi