wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Visual C# Quiz - Chapter 5: Loops, Files, and Random Numbers

Total questions: 15

Worksheet time: 11mins

Name
Class
Date
1.

What does a while loop do?

a)

Does not execute any statements

b)

Repeats a statement until a Boolean expression is true

c)

Executes a statement only once

d)

Repeats a statement as long as a Boolean expression is true

2.

What is the structure of a while loop?

a)

if (BooleanExpression) { statements }

b)

do { statements } while (BooleanExpression)

c)

for (Initialization; Test; Update) { statements }

d)

while (BooleanExpression) { statements }

3.

What type of loop is a while loop considered?

a)

Pretest loop

b)

Counter loop

c)

Posttest loop

d)

Infinite loop

4.

What happens if the condition of a while loop is false at the start?

a)

The loop will cause an error

b)

The loop will iterate indefinitely

c)

The loop will iterate at least once

d)

The loop will not iterate at all

5.

What is an infinite loop?

a)

A loop that executes a fixed number of times

b)

A loop that never starts

c)

A loop that repeats until interrupted

d)

A loop that executes only once

6.

What do the ++ and -- operators do?

a)

Multiply and divide a variable

b)

Reset a variable to zero

c)

Add and subtract a variable

d)

Increment and decrement a variable

7.

What is the general format of a for loop?

a)

for (Initialization; Test; Update) { statements }

b)

while (BooleanExpression) { statements }

c)

do { statements } while (BooleanExpression)

d)

if (BooleanExpression) { statements }

8.

What is the purpose of the StreamWriter class?

a)

To read data from a text file

b)

To write data to a text file

c)

To delete a file

d)

To create a new file

9.

What does the OpenFileDialog control do?

a)

Deletes a file

b)

Creates a new file

c)

Displays a dialog box for opening files

d)

Displays a dialog box for saving files

10.

Aiden is working on a project in .NET and needs to generate random numbers for his simulation. What is the purpose of the Random class in .NET?

a)

To sort numbers

b)

To display numbers

c)

To generate random numbers

d)

To store numbers in a file

11.

During a computer science class, Priya is curious about the NextDouble method of the Random class. What does this method return?

a)

An integer between 0 and 100

b)

A floating-point number between 0.0 and 1.0

c)

A random string

d)

A boolean value

12.

What is the Load event in an application that Olivia is developing?

a)

An event that occurs when a file is saved

b)

An event that occurs when the application is closed

c)

An event that occurs when the form is loaded into memory

d)

An event that occurs when a button is clicked

13.

Sophia is learning about file handling in her programming class. What is the purpose of the Close method in file handling?

a)

To read data from a file

b)

To write data to a file

c)

To open a file

d)

To disconnect the file and the program

14.

What is the difference between a for loop and a while loop?

a)

A for loop is used for iterating over arrays, while a while loop is not

b)

A for loop has a defined number of iterations, while a while loop continues until a condition is false

c)

A for loop can only be used with integers, while a while loop can be used with any data type

d)

There is no difference; they are interchangeable

15.

What does the StreamReader class do in file handling?

a)

To write data to a file

b)

To read data from a file

c)

To delete a file

d)

To create a new file