PrepAway - Latest Free Exam Questions & Answers

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.)

PrepAway - Latest Free Exam Questions & Answers

Answer:

17 Comments on “Which code should you insert at line 04?

  1. 宾宾 says:

    The answer is:
    //modify the vlaue of en-us to Culture.
    Thread.CurrentThread.CurrentCulture = new CultureInfo(“en-us”);
    string msg = string.Format(“Temperature at {0:t} on {0:d} : {1:N2}”, DateTime.Now, 20);




    3



    0
  2. Jiping Wang says:

    {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




    1



    0
    1. Artem says:

      {0:d} and {0:t} is culture specific. For me this code print
      time=23:43 date=14.02.2017
      If I add before
      Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
      then work correctly.




      0



      0
  3. ghefar says:

    Wrong available answers!!!
    Hour: The question gives this example 2:00 PM
    -> 2 and not 02!
    -> PM/AM
    This can be achieved like this: “{0:h:mm tt}”. However, this is not in the list!

    Month: It asks for teh formatt month/day/year (and not day/month/year)
    This can be achieved liek this:{0:MM/dd/yyyy}”




    2



    0

Leave a Reply