1_ What is the output? private void btnMethods_Click(object sender, EventArgs e)
ID: 3799798 • Letter: 1
Question
1_ What is the output?
private void btnMethods_Click(object sender, EventArgs e)
{
int arg1 = 2;
double val = ValReturnMethod(arg1, 2.00);
MessageBox.Show(val.ToString());
}
private void ValReturnMethod(int val, double val2)
{
return val1 * val2 *25.50;
}
_____________________________
2_ What is the output?
private void btnMethods_Click(object sender, EventArgs e)
{
int arg1 = 4;
double val = ValReturnMethod(ref arg1);
MessageBox.Show(arg1.ToString());
}
private double ValReturnMethod(ref int val1)
{
return val1 *25.50;
}
______________________________
3_ What is the output?
private void btnMethods_Click(object sender, EventArgs e)
{
int arg1 = 4;
double arg2 = 10.50;
MessageBox.Show(ValReturnMethod(arg1,arg2).ToString());
}
private double ValReturnMthod (int val1,double val2)
{
return val1 * 25.50;
}
Explanation / Answer
1_ What is the output?
private void btnMethods_Click(object sender, EventArgs e)
{
int arg1 = 2;
double val = ValReturnMethod(arg1, 2.00);
MessageBox.Show(val.ToString());
}
private void ValReturnMethod(int val, double val2)
{
return val1 * val2 *25.50; //This is trying to return a value from a void method, which leads to error.
//Also there is a typo. The variable val1 is used here, where it is declared as val.
}
_____________________________
2_ What is the output?
private void btnMethods_Click(object sender, EventArgs e)
{
int arg1 = 4;
double val = ValReturnMethod(ref arg1); //val1 is assigned with 102.
MessageBox.Show(arg1.ToString()); //And 102 will be printed to MessageBox.
}
private double ValReturnMethod(ref int val1)
{
return val1 *25.50; //val1 = 4 is taken as input. And returns 4 * 25.50 = 102.
}
______________________________
3_ What is the output?
private void btnMethods_Click(object sender, EventArgs e)
{
int arg1 = 4;
double arg2 = 10.50;
MessageBox.Show(ValReturnMethod(arg1,arg2).ToString()); //Calling a method that doesn't exist.
//Note there is a typo in the other method. ValReturnMthod.
//If not that, this will also return 102.
}
private double ValReturnMthod (int val1,double val2)
{
return val1 * 25.50; //Returns 4 * 25.50
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.