Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C# Data Types and Operations

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is type conversion in C#?

a)

Type conversion in C# is the act of renaming a variable to improve readability.

b)

Type conversion in C# is the process of converting a variable from one data type to another, either implicitly or explicitly.

c)

Type conversion in C# is the process of changing the color of a variable.

d)

Type conversion in C# refers to the method of optimizing memory usage.

2.

Explain implicit type conversion with an example.

a)

Example: In JavaScript, `5 + 5` results in `10` because both are numbers.

b)

Example: In JavaScript, `5 + '5'` results in `'55'` because the number 5 is implicitly converted to a string.

c)

Example: In JavaScript, `5 - '5'` results in `0` because the string is ignored.

d)

Example: In JavaScript, `5 * '5'` results in `25` because the string is converted to a number.

3.

What is explicit type conversion?

a)

Explicit type conversion is the same as type inference.

b)

Explicit type conversion is the intentional conversion of a variable from one data type to another.

c)

Type conversion only occurs in programming languages with dynamic typing.

d)

Implicit type conversion is automatic and unintentional.

4.

How do you convert a string to an integer in C#?

a)

Use int.Parse() or Convert.ToInt32() methods.

b)

Use Convert.ToString() method.

c)

Use string.ToInteger() method.

d)

Use float.Parse() to convert the string.

5.

What is the purpose of the 'as' operator in C#?

a)

The 'as' operator is used for exception handling.

b)

The 'as' operator is used for creating new classes.

c)

The 'as' operator is used for safe type casting.

d)

The 'as' operator is used for defining variables.

6.

What is the difference between 'is' and 'as' operators?

a)

'is' checks type; 'as' checks identity.

b)

'is' performs type casting; 'as' checks equality.

c)

'is' checks value; 'as' checks reference.

d)

'is' checks identity; 'as' performs type casting.

7.

What are the arithmetic operators available in C#?

a)

+, -, *, /, %

b)

<, >, <=, =>

c)

++, --, **, //

d)

&, |, ^, ~

8.

How do you perform a modulus operation in C#?

a)

Use the 'mod' function to perform a modulus operation.

b)

Use the '%' operator to perform a modulus operation.

c)

Use the '#' operator to perform a modulus operation.

d)

Use the '%' symbol for division instead of modulus.

9.

What is the result of 5 / 2 in C#?

a)

3

b)

2

c)

2.5

d)

1

10.

Explain the use of the increment (++) operator in C#.

a)

The increment (++) operator multiplies a variable's value by two in C#.

b)

The increment (++) operator increases a variable's value by one in C#.

c)

The increment (++) operator is used to concatenate strings in C#.

d)

The increment (++) operator decreases a variable's value by one in C#.

11.

What is the difference between '==' and '===' in C#?

a)

'==' checks for reference equality only.

b)

'==' and '===' are interchangeable in C#.

c)

'==' checks for value equality with type conversion, while '===' does not exist in C#.

d)

'===' checks for value equality with type conversion.

12.

How do you concatenate two strings in C#?

a)

Using the '-' operator

b)

Using String.Join method

c)

Using StringBuilder only

d)

You can concatenate two strings in C# using the '+' operator or String.Concat method.

13.

What is the purpose of the '??' operator in C#?

a)

The '??' operator is used for string concatenation.

b)

The '??' operator checks if a variable is of type string.

c)

The '??' operator performs addition between two numbers.

d)

The '??' operator returns the left-hand operand if it is not null; otherwise, it returns the right-hand operand.

14.

How can you check if a variable is of a certain type in C#?

a)

Use 'variable == TypeName'

b)

Use 'variable is TypeName' or 'variable.GetType() == typeof(TypeName)'

c)

Check variable type with 'TypeName(variable)'

d)

Use 'typeof(variable) == TypeName'

15.

What is the precedence of operators in C#?

a)

Unary operators have the highest precedence

b)

Bitwise OR is evaluated before Logical AND

c)

Conditional operators are evaluated first

d)

Operators in C# are evaluated in the following order (from highest to lowest): 1. Parentheses, 2. Unary operators (++, --, +, -), 3. Multiplicative (*, /, %), 4. Additive (+, -), 5. Shift (<<, >>), 6. Relational (<, >, <=, >=), 7. Equality (==, !=), 8. Bitwise AND (&), 9. Bitwise XOR (^), 10. Bitwise OR (|), 11. Logical AND (&&), 12. Logical OR (||), 13. Conditional (?:), 14. Assignment (=, +=, -=, etc.).