Guest User

Untitled

a guest
Jan 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Program
  5. {
  6. public static void Main()
  7. {
  8. List<string> list = new List<string>{ "1", "2", "3"};
  9. Utils utils = new Utils();
  10. utils.ChangeType(list, typeof(List<int>));
  11. Console.WriteLine("Done!");
  12. }
  13. }
  14.  
  15. public class Utils
  16. {
  17. public object ChangeType(object obj, Type type)
  18. {
  19. return Convert.ChangeType(obj, type);
  20. }
  21. }
  22.  
  23. Run-time exception (line 19): Object must implement IConvertible.
  24.  
  25. Stack Trace:
  26.  
  27. [System.InvalidCastException: Object must implement IConvertible.]
  28. at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
  29. at System.Convert.ChangeType(Object value, Type conversionType)
  30. at Utils.ChangeType(Object obj, Type type) :line 19
  31. at Program.Main() :line 10
Add Comment
Please, Sign In to add comment