0
0
C Sharp (C#)programming~5 mins

Format specifiers for numbers and dates in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the format specifier "C" do when formatting numbers in C#?
The "C" specifier formats a number as currency, adding the currency symbol and two decimal places by default.
Click to reveal answer
beginner
How do you format a DateTime to show only the year and month in C#?
Use the format specifier "yyyy-MM" with DateTime.ToString(), which shows the full year and two-digit month.
Click to reveal answer
intermediate
What is the difference between "D" and "d" format specifiers for dates in C#?
"D" shows the long date pattern (e.g., "Monday, June 5, 2023"), while "d" shows the short date pattern (e.g., "6/5/2023").
Click to reveal answer
beginner
How does the "N" format specifier format numbers in C#?
"N" formats numbers with thousands separators and two decimal places by default (e.g., "1,234.56").
Click to reveal answer
beginner
What does the format specifier "F" do when formatting numbers?
"F" formats a number as a fixed-point number with a default of two decimal places (e.g., "1234.56"). You can specify decimals like "F3" for three decimals.
Click to reveal answer
Which format specifier would you use to display a number as currency in C#?
A"F"
B"N"
C"D"
D"C"
What does the "d" format specifier show when formatting a DateTime?
AShort date pattern (e.g., 6/5/2023)
BLong date pattern (e.g., Monday, June 5, 2023)
CTime only
DFull date and time
How would you format a number with thousands separators and two decimals in C#?
A"C"
B"F"
C"N"
D"P"
Which format specifier shows the full year and month in a DateTime string?
A"yyyy-MM"
B"d"
C"D"
D"F"
What does the "F3" format specifier do when formatting a number?
AFormats as currency with 3 decimals
BFormats as fixed-point with 3 decimals
CFormats as number with thousands separators
DFormats as percentage with 3 decimals
Explain how to format a number as currency and as a fixed-point number in C#.
Think about how money and precise decimals look.
You got /4 concepts.
    Describe the difference between the "D" and "d" date format specifiers in C#.
    One is detailed, the other is brief.
    You got /4 concepts.