Проход по полям класса - C#
Формулировка задачи:
Здравствуйте. Есть класс
Как можно сделать так, чтоб в дальнейшем уметь проходить foreach()-ем по полям класса? Слышал об интерфейсе INumerable, но не знаю подойдет ли он для таких целей?! Или же нужно все-таки поля внести в какую-либо коллекцию? (Например, ArrayList?)
static class Data
{
public static string _CompanyName;
public static string _EmailLogin;
public static string _Password;
public static string _SmtpAddress;
public static int _SmtpPort;
public static bool _EnableSSL;
public static bool _EnableHTML;
public static int _IntervalBetween;
public static int _QuantityForDay;
public static string _TestAddress;
public static List<string> _Destination;
}Решение задачи: «Проход по полям класса»
textual
Листинг программы
int i = 0;
Type type = typeof(Data);
FieldInfo[] fields = type.GetFields();
object[] arrObj = new object[fields.Length];
foreach (FieldInfo field in fields)
{
arrObj[i++] = field.GetValue(null);
}