Which code should you insert at line 04?

HOTSPOT
You are developing an application in C#.
The application will display the temperature and the time at which the temperature was recorded.
You have the following method (line numbers are included for reference only):

You need to ensure that the message displayed in the lblMessage object shows the time formatted
according to the following requirements:
The time must be formatted as hour:minute AM/PM, for example 2:00 PM.
The date must be formatted as month/day/year, for example 04/21/2013.
The temperature must be formatted to have two decimal places, for example 23-45.
Which code should you insert at line 04? (To answer, select the appropriate options in the answer
area.)

HOTSPOT
You are developing an application in C#.
The application will display the temperature and the time at which the temperature was recorded.
You have the following method (line numbers are included for reference only):

You need to ensure that the message displayed in the lblMessage object shows the time formatted
according to the following requirements:
The time must be formatted as hour:minute AM/PM, for example 2:00 PM.
The date must be formatted as month/day/year, for example 04/21/2013.
The temperature must be formatted to have two decimal places, for example 23-45.
Which code should you insert at line 04? (To answer, select the appropriate options in the answer
area.)

Answer:



Leave a Reply 13

Your email address will not be published. Required fields are marked *


Pete

Pete

date formatting should be {0:mm/dd/yy}, but that option is not shown in the list.

sv1slim

sv1slim

Don’t forget that DateTime format also includes time not only date. Should be something like that:
var output = string.Format(“Temperature at {0:hh:mm} on {0:dd/mm/yy} is {1:N2}”, date, temp);

Najlepszy Programista Swiata DAGO

Najlepszy Programista Swiata DAGO

there is no correct answer, should be:

output = string.Format(“Temperature at {0:hh:mm tt} on {0:MM/dd/yyyy}, temp: {1:N2}”, date, temp);

Ashraf

Ashraf

Based on testing, {0:d} is the best choice for formatting the the date.

Caret

Caret

Temperature at 21-03-2017 12:39:19 on 12:39 21-03-2017 – {0} on {0:t} {0:d}
Temperature at 23,453 on 12:39 21-39-17 – {1} on {0:hh:mm} {0:dd/mm/yy}
Temperature at 23,45 on 12:39 03-21-17 – {1:N2} on {0:hh:mm} {0:MM/dd/yy}

Lord Vader

Lord Vader

{0:t} displays argument 0 with short times(2:15pm)
{0:d} displayed argument 0 with short date(3/14/2017)
{1:N2} displays argument 1 with 2 decimal

Jiping Wang says:
May 10, 2016 at 10:14 am
{0:t}
{0:d}
{1:N2}

confirmed in Visual Studio:

string.Format(“time={0:t} date={0:d} temp={1:N2}”, DateTime.Now, 2)
——————————————
time=01:24 AM date=05/10/2016 temp=2.00

hed

hed

but first we need to choose the correct culture.