Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- List<string> list = new List<string>{ "1", "2", "3"};
- Utils utils = new Utils();
- utils.ChangeType(list, typeof(List<int>));
- Console.WriteLine("Done!");
- }
- }
- public class Utils
- {
- public object ChangeType(object obj, Type type)
- {
- return Convert.ChangeType(obj, type);
- }
- }
- Run-time exception (line 19): Object must implement IConvertible.
- Stack Trace:
- [System.InvalidCastException: Object must implement IConvertible.]
- at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
- at System.Convert.ChangeType(Object value, Type conversionType)
- at Utils.ChangeType(Object obj, Type type) :line 19
- at Program.Main() :line 10
Add Comment
Please, Sign In to add comment