Hey all.

I two subs that are almost exactly identical that return two different types of control


I would use the sub something like

textbox1.text = stringtoMatchtype1("match1").chatter;

where chatter is a property of matchtype1(and 2)

I could just return a control but then i couldnt access the propertys and methods of that contorl.



any ideas to point me down a better path?

c# Code:
  1. private MatchType1 StringToMatchType1(string name)
  2.         {
  3.             foreach (TabPage tp in tabControl1.Controls)
  4.             {
  5.                 foreach (Control c in tp.Controls)
  6.                 {
  7.                     if (c is MatchType1)
  8.                     {
  9.                         if (c.Name == name)
  10.                         {
  11.                             return (MatchType1)c;
  12.                         }
  13.                     }
  14.                 }
  15.             }
  16.             throw new Exception("Matchtype1 not found" + name);
  17.         }
  18.         private MatchType2 StringToMatchType2(string name)
  19.         {
  20.             foreach (TabPage tp in tabControl1.Controls)
  21.             {
  22.                 foreach (Control c in tp.Controls)
  23.                 {
  24.                     if (c is MatchType2)
  25.                     {
  26.                         if (c.Name == name)
  27.                         {
  28.                             return (MatchType2)c;
  29.                         }
  30.                     }
  31.                 }
  32.             }
  33.             throw new Exception("Matchtype2 not found" + name);
  34.         }