1 What is the output private void btnMethodsClickobject send

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;

}

Solution

=======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

1_ What is the output? private void btnMethods_Click(object sender, EventArgs e) { int arg1 = 5; TestMethod(ref arg1); MessageBox.Show(arg1.ToString()); } priva
1_ What is the output? private void btnMethods_Click(object sender, EventArgs e) { int arg1 = 5; TestMethod(ref arg1); MessageBox.Show(arg1.ToString()); } priva

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site