This quiz covers most common string formatting and datetime formatting methods
This quiz is in C# .NET quiz collection.
Start quizWhat is the result?
Decimal pricePerOunce = 17.36m;
String s = String.Format("The current price is {0} per ounce.",
pricePerOunce);
What is the result?
Decimal pricePerOunce = 17.36m;
String s = String.Format("The current price is {0:C2} per ounce.",
pricePerOunce);
What is the valid result of s?
string s = String.Format("It is now {0:d} at {0:t}", DateTime.Now);
What is the output?
int[] years = { 2013, 2014, 2015 };
int[] population = { 1025632, 1105967, 1148203 };
String s = String.Format("{0,-10} {1,-10}\n\n", "Year", "Population");
for(int index = 0; index < years.Length; index++)
s += String.Format("{0,-10} {1,-10:N0}\n",
years[index], population[index]);
What is the output?
DateTime dat = new DateTime(2017, 1, 17, 9, 30, 0);
string city = "Chicago";
int temp = -16;
string output = String.Format("At {0} in {1}, the temperature was {2} degrees.",
dat, city, temp);
Console.WriteLine(output);
What is the output?
int value;
value = 12345;
Console.WriteLine(value.ToString("D"));
What is the result?
decimal value = 123.456m;
Console.WriteLine("Your account balance is {0:C2}.", value);
What is the output?
double value = 12345.6789;
Console.WriteLine(value.ToString("E", CultureInfo.InvariantCulture));
What is the output?
double value = 12345.6789;
Console.WriteLine(value.ToString("E10", CultureInfo.InvariantCulture));
What is the ouput?
int integerNumber;
integerNumber = 17843;
Console.WriteLine(integerNumber.ToString("F",
CultureInfo.InvariantCulture));
© 2017 QuizBucket.org