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: 3799749 • Letter: 1

Question

1_ What is the output?

private void btnMethods_Click(object sender, EventArgs e)

{

int arg1 = 5;

TestMethod(ref arg1);

MessageBox.Show(arg1.ToString());

}

private void TestMthod (ref int val)

{

val = 2 * val;

}

2_ Why is this an error?

private void btnMethods_Click(object sender, EventArgs e)

{

int arg1 = 5;

TestMethod(out arg1);

MessageBox.Show(arg1.ToString());

}

private void TestMthod (out int val)

{

val = 2 * val;

}

3_ Why is this an error?

private void btnMethods_Click(object sender, EventArgs e)

{

int arg1 = 5.5;

TestMethod(arg1);

MessageBox.Show(arg1.ToString());

}

private void TestMthod (decimal val)

{

val = 2 * val;

}

Explanation / Answer

=======1========

Since, type int is passed by value

Hence, when we print arg1, it would still be 5

========2===========

While using out means that you will not be able to assume that the parameter has already been populated. You will not be able to read its value inside the method. So, the compile error is because no value has been assigned to i.

==========3==========

you have defined arg1 as type int but are assigning a decimal value. Hence the error

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