PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You are developing an application that includes methods named ConvertAmount and TransferFunds.
You need to ensure that the precision and range of the value in the amount variable is not lost when the
TransferFunds() method is called.
Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
Option A

B.
Option B

C.
Option C

D.
Option D

Explanation:
The double keyword signifies a simple type that stores 64-bit floating-point values.
The float keyword signifies a simple type that stores 32-bit floating-point values.
double (C# Reference)

5 Comments on “Which code segment should you use?

  1. upmass says:

    A – it’s incorrect answer.

    With A – ConvertAmount(2.02f) – output will be 2,01999998092651
    With B – ConvertAmount(2.02f) – output will be 2.02 without lost

    Correct answer is B




    16



    2
  2. Seamus says:

    Answer is B

    class Program
    {
    static void Main(string[] args)
    {
    Question15 q15 = new Question15();
    q15.ConvertAmount(2.02f);
    Console.ReadKey();
    }
    }

    public class Question15
    {
    public void ConvertAmount(float amount)
    {
    TransferFunds((decimal)amount);
    }
    private void TransferFunds(decimal funds)
    {
    Console.WriteLine(funds);
    }
    }




    6



    1

Leave a Reply