// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Reflection; public class MainClass { public static void DynSet(Object o, string[] vals) { FieldInfo[] fields = o.GetType().GetFields(); for(int i = 0; i < fields.Length; i++) { fields[i].SetValue(o, vals[i]); } } public static void Main(string[] args) { A a = new A(); string[] vals = { "a", "bb", "ccc" }; DynSet(a, vals); Console.WriteLine(a.a + " " + a.b + " " + a.c); } } public class A { public string a; public string b; public string c; }