Question : Function to return a boolean and 2 strings

Hi,

I want to write a function that returns a boolean value, and 2 strings, see attached code.  What am I doing wrong here?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
public string ValidatePropPlant(Boolean valid, string Total1, string Total2)
   {
       valid = true;
       foreach (Control item in this.Controls)
       {
          ScheduleH = new SchedH();
          if (curr_PropPlantEquipTextBox.Text != ScheduleH.landBuildText.Text)
       {
          Total1 = curr_PropPlantEquipTextBox.Text;
           Total2 = ScheduleH.landBuildText.Text;
           valid = false;
       }
    }
        return valid;
        return Total1;
        return Total2;
}

Answer : Function to return a boolean and 2 strings

Hmm, it ate my snippet :-(

You have a couple choices as outlined above.  Here are examples using both the output parameters and a complex return type.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
// option 1 output parameters
// called like
private void Validation_Click(object sender, EventArgs e)
{
	string Total1, Total2; 
	if (ScheduleF.ValidatePropPlant(out Total1, out Total2) == false)
	{
		MessageBox.Show("Total" + Total1 + "should be equal to" + Total2);
	}
} 
public bool ValidatePropPlant(out string Total1, out string Total2)
{
	bool RetVal = true;
	Total1 = Total2 = string.Empty; 
	foreach (Control item in this.Controls)
	{
		ScheduleH = new SchedH();
		if (curr_PropPlantEquipTextBox.Text != ScheduleH.landBuildText.Text)
		{
			Total1 = curr_PropPlantEquipTextBox.Text;
			Total2 = ScheduleH.landBuildText.Text;
			RetVal = false;
		}
	} 
	return RetVal;
} 

// option 2 complex return type
// called like
public struct ReturnType
{
	public bool Valid { get; set; }
	public string Total1 { get; set; }
	public string Total2 { get; set; }
} 
private void Validation_Click(object sender, EventArgs e)
{
	ReturnType RT = ScheduleF.ValidatePropPlant(); 
	if (RT.Valid == false)
	{
		MessageBox.Show("Total" + RT.Total1 + "should be equal to" + RT.Total2);
	}
} 
public bool ValidatePropPlant()
{
	ReturnType RT = new ReturnType();
	RT.Valid = true; 
	foreach (Control item in this.Controls)
	{
		ScheduleH = new SchedH();
		if (curr_PropPlantEquipTextBox.Text != ScheduleH.landBuildText.Text)
		{
			RT.Total1 = curr_PropPlantEquipTextBox.Text;
			RT.Total2 = ScheduleH.landBuildText.Text;
			RT.Valid = false;
		}
	} 
	return RT;
}
Random Solutions  
 
programming4us programming4us