public static void Main() { ListOfVariablesToSave myListOfVariablesToSave = new ListOfVariablesToSave(); myListOfVariablesToSave.ForEach(m => { Console.WriteLine(m.Name); m.ForEach(m1 => Console.WriteLine(m1)); }); }
public static void Main() { ListOfVariablesToSave myListOfVariablesToSave = new ListOfVariablesToSave(); foreach (PropertyInfo pi in myListOfVariablesToSave .GetType() .GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly) ) { Console.WriteLine(pi.Name); // This only works if your properties are List<int>, // other property types will throw an exception (pi.GetValue(myListOfVariablesToSave) as List <int>).ForEach(i => Console.WriteLine(i)); } }
public static void Main() { ListOfVariablesToSave myListOfVariablesToSave = new ListOfVariablesToSave(); foreach (PropertyInfo pi in myListOfVariablesToSave .GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) // Only get the properties of type List<int> // Actual PropertyType looks like: // System.Collections.Generic.List`1[System.Int32] .Where(p => p.PropertyType.ToString().Contains("List") && p.PropertyType.ToString().Contains("System.Int32")) ) { Console.WriteLine(pi.Name); (pi.GetValue(myListOfVariablesToSave) as List <int>).ForEach(i => Console.WriteLine(i)); } }