Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1_ What is the output? private void btnMethods_Click(object sender, EventArgs e)

ID: 3799778 • Letter: 1

Question

1_ What is the output?

private void btnMethods_Click(object sender, EventArgs e)

{

decimal arg1 =5.50;

TestMethod(2,ref arg1);

MessageBox.Show(arg1.ToString());

}

private void TestMthod (int factor , ref decimal val)

{

val = factor * val;

}

_________________________________

2_ What is the output?

private void btnMethods_Click(object sender, EventArgs e)

{

double val = ValReturnMethod();

MessageBox.Show(val.ToString());

}

private double ValReturnMethod()

{

return 25.50;

}

__________________________________

3_ What is the output?

private void btnMethods_Click(object sender, EventArgs e)

{

int arg1 = 2;

double val = ValReturnMethod(arg1);

MessageBox.Show(arg1.ToString());

}

private double ValReturnMethod(int val1)

{

return 25.50 * val1;

}

Explanation / Answer

Answer-1)

It will generate error "Literal of type double cannot be inplicitly converted to type 'decimal'; use an 'M' suffix to create a literal of this type"

Here, '5.5' is of type double and arg1 is of type decimal.

In order to convert double into decimal, you can use either of the alternative:

First) decimal arg1 = (decimal) 5.5; //It will explicitly typecast double into decimal

Second) decimal arg1 = 5.5M; // M/m is used to treat real number as a decimal

Answer-2 )

"return 25.50 " statement in ValReturnMethod() alwarys return truncated value.

If you return

MessageBox.Show(val.ToString()) displays message box with return value as a string.

val.ToString() method converts value of val variable into string.

Answer-3)

In the statement "return 25.50 * val1", val1 will be casted to double implicitly. Then multiplication will be performed and result is returned.

Further return value will be converted into string and will get displayed via messagebox

Value Output 25.500 25.5 25.000 25
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote