Sie können GetType folgendermaßen verwenden:
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ConsoleApplication1
{
class Program
{
static IList<Control> controls;
static void Main(string[] args)
{
controls = new List<Control>();
controls.Add(new TextBox());
controls.Add(new CheckBox());
foreach (var control in controls)
{
Console.WriteLine(control.GetType());
}
Console.ReadLine();
}
}
}
Sie können auch ein Wörterbuch einrichten, wenn Ihnen das lieber ist:
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ConsoleApplication1
{
class Program
{
static IDictionary<string, Control> controls;
static void Main(string[] args)
{
controls = new Dictionary<string, Control>();
controls.Add("textbox thing", new TextBox());
controls.Add("checkbox thing", new CheckBox());
foreach (var control in controls)
{
Console.WriteLine(control.Key);
}
Console.ReadLine();
}
}
}
Oder Sie könnten das Steuerelement als Eigenschaft in Klasse A hinzufügen und die IList auf IList<ClassA> setzen:
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ConsoleApplication1
{
class ClassA
{
public Control Control { get; set; }
public string Group { get; set; }
public string Subgroup { get; set; }
}
class Program
{
static IList<ClassA> controls;
static void Main(string[] args)
{
controls = new List<ClassA>();
controls.Add(new ClassA
{
Control = new TextBox(),
Group = "Input",
Subgroup = "Text"
});
controls.Add(new ClassA
{
Control = new CheckBox(),
Group = "Input",
Subgroup = "Checkbox"
});
foreach (var control in controls)
{
Console.WriteLine(control.Subgroup);
}
Console.ReadLine();
}
}
}