Complete the code to format the number as currency.
double price = 1234.56; string formatted = price.ToString("[1]"); Console.WriteLine(formatted);
The format specifier C formats the number as currency.
Complete the code to format the date as year-month-day.
DateTime today = new DateTime(2024, 6, 15); string formatted = today.ToString("[1]"); Console.WriteLine(formatted);
The format specifier yyyy-MM-dd formats the date as year-month-day.
Fix the error in the code to format a number with two decimal places.
double value = 3.14159; string result = value.ToString("[1]"); Console.WriteLine(result);
The format specifier F2 formats the number with two decimal places.
Fill both blanks to format the date as full month name and 24-hour time.
DateTime dt = new DateTime(2024, 6, 15, 18, 30, 0); string formatted = dt.ToString("[1] [2]"); Console.WriteLine(formatted);
MMMM shows the full month name, and HH:mm shows 24-hour time with minutes.
Fill all three blanks to create a dictionary with word lengths for words longer than 3 letters.
string[] words = {"apple", "bat", "carrot", "dog"};
var lengths = new Dictionary<string, int>()
{
{"[1]", [2]
};
foreach (var word in words)
{
if (word.Length [3] 3)
{
lengths[word] = word.Length;
}
}
foreach (var kvp in lengths)
{
Console.WriteLine($"{kvp.Key}: {kvp.Value}");
}The dictionary key is the word (word), the value is its length (word.Length), and the condition checks if length is greater than 3 (>).
