fork download
  1. using System;
  2. using static System.Console;
  3. using System.Reflection;
  4.  
  5. public class Program {
  6. public static void Main() {
  7. int i = 0;
  8. Objeto obj = new Objeto();
  9. string[] array = { "1", "01/01/2015", "abc", "0.123" };
  10. foreach(PropertyInfo inf in typeof(Objeto).GetProperties()) {
  11. inf.SetValue(obj, Convert.ChangeType(array[i], inf.PropertyType));
  12. i++;
  13. }
  14. WriteLine($"Número: {obj._numero}");
  15. WriteLine($"Número: {obj._data}");
  16. WriteLine($"Número: {obj._palavra}");
  17. WriteLine($"Número: {obj._decimal}");
  18. }
  19. }
  20.  
  21. public class Objeto {
  22. public int _numero { get; set; }
  23. public DateTime _data { get; set; }
  24. public string _palavra { get; set; }
  25. public decimal _decimal { get; set; }
  26. }
  27.  
  28. //https://pt.stackoverflow.com/q/53143/101
Success #stdin #stdout 0.03s 18212KB
stdin
Standard input is empty
stdout
Número: 1
Número: 1/1/2015 12:00:00 AM
Número: abc
Número: 0.123