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

Composite formatting in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print the name using composite formatting.

C Sharp (C#)
string name = "Alice";
Console.WriteLine("Hello, [1]!", name);
Drag options to blanks, or click blank then click option'
A"{0}"
B"{name}"
C"name"
D"{}"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name inside the string without braces.
Using empty braces {} which is invalid in C# composite formatting.
2fill in blank
medium

Complete the code to print the age using composite formatting.

C Sharp (C#)
int age = 30;
Console.WriteLine("Age: [1]", age);
Drag options to blanks, or click blank then click option'
A"{age}"
B"{1}"
C"{}"
D"{0}"
Attempts:
3 left
💡 Hint
Common Mistakes
Using {1} when there is only one argument.
Using variable names inside braces which is not supported in composite formatting.
3fill in blank
hard

Fix the error in the composite formatting to print both name and age.

C Sharp (C#)
string name = "Bob";
int age = 25;
Console.WriteLine("Name: [1], Age: {1}", name, age);
Drag options to blanks, or click blank then click option'
A"{name}"
B"{}"
C"{0}"
D"{2}"
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names inside braces instead of numbers.
Using {2} when only two arguments are provided.
4fill in blank
hard

Fill both blanks to format a floating number with 2 decimal places and align it right in 10 spaces.

C Sharp (C#)
double price = 123.456;
Console.WriteLine("Price: [1], Total: [2]", price, price * 2);
Drag options to blanks, or click blank then click option'
A"{0,10:F2}"
B"{0:F2}"
C"{1,10:F2}"
D"{1:F2}"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indexes for placeholders.
Omitting alignment or format specifier.
5fill in blank
hard

Fill all three blanks to print a formatted string with name uppercase, age, and balance with currency format.

C Sharp (C#)
string name = "Carol";
int age = 40;
double balance = 1234.5;
Console.WriteLine("Name: [1], Age: [2], Balance: [3]", name.ToUpper(), age, balance);
Drag options to blanks, or click blank then click option'
A"{0}"
B"{1}"
C"{2:C}"
D"{0:C}"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up argument indexes.
Forgetting the currency format specifier.