protected void Button4_Click(object sender, EventArgs e) { RefOutExample refOutObj = new RefOutExample(); refOutObj.RefOutExtensionMethod(5); TextBox3.Text = "After calling the RefOutExtension Method with the value 5," + "the new value of outParam variable is :" + refOutObj.outParam; }
protected void Button3_Click(object sender, EventArgs e) { RefOutExample refOutObj = new RefOutExample(); TextBox2.Text = "Variables: refParam = " + refOutObj.refParam + "\nrefArray[0] = " + refOutObj.refArray[0] + "\nwithoutRefParam = " + refOutObj.withoutRefParam + "\noutParam = " + refOutObj.outParam + "\n\nCalling the method by ref.."; refOutObj.RefMethod(refOutObj.refArray, ref refOutObj.refParam, refOutObj.withoutRefParam); TextBox2.Text += "\nNew values of the original variables after calling RefMethod are," + "\nrefParam = " + refOutObj.refParam + "\nrefArray[0] = " + refOutObj.refArray[0] + "\nand withoutRefParam = " + refOutObj.withoutRefParam + "\n\nNow calling the OutMethod.."; refOutObj.OutMethod(out refOutObj.outParam); TextBox2.Text += "\nThe outParam variable was declared but not initialized" + " \nhowever, after calling the OutMethod, " + "\noutParam = " + refOutObj.outParam; }
public static void RefOutExtensionMethod(this RefOutExample a, int value) { a.outParam += value; }