This quiz covers the key concepts of C# string formatting, focusing on the Format()
method and its various format controls. You’ll be tested on how to use placeholders, format numbers, apply different format specifiers (such as currency, hexadecimal, percentages, and more), and handle string manipulations using the Format()
method. This is an essential part of mastering string handling in C# and will help you better control how your data is displayed and formatted in your applications.
1.
What will the output of this code be?
string.Format("The value {0:N} is formatted.", 12345.6789);
2.
What does the {0:E6} format control do?
3.
Which format control would you use to display a number with leading zeros?
4.
Which method allows you to format a number as a percentage?
5.
What does the {0:D4} format control output for the number 43?
6.
What does the F format control do?
7.
How would you format a number as currency in C#?
8.
Which format control would you use to display a number in human-friendly format with commas?
9.
What is the correct way to format a number with zero padding?
10.
How would you display the number 255 as a hexadecimal value?
11.
What is the primary purpose of the C# string Format() method?
12.
Which of the following format controls is used to add spaces for padding in a formatted string?
13.
What would the following code output?
string.Format("The percentage is {0:0.00%}.", 0.45);
14.
Which format control would you use to display a number with a fixed number of decimal places?
15.
What would the output of this code be?
string.Format("The number {0:D4} is a padded number.", 45);?
16.
Which format control would you use to display a number in exponential form?
17.
What would the following code output?
string.Format("The number {0:C} is the price.", 99.99);
18.
Which placeholder format is used to display a number in hexadecimal format?
19.
What does the following code output?
string.Format("There are {0} apples and {1} oranges.", 4, 6);
20.
What does the placeholder {0} signify in the string.Format method?