Run Code  | Code Wall  | Users  | Misc  | Feedback  | About  | Login  | Theme  | Stackse 

Invalid cast

      
            
                
            
 run  | edit  | history  | help 1

ASDASDASSD

  by  alaestor, 3 months ago


using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions;

namespace Rextester { public class Program { public static void Main(string[] args) { int longVariable = 6; int intVariable = ConvertToType<int>(ref longVariable); Console.WriteLine(intVariable); //Console.ReadKey(); }

    private static T ConvertToType<T>(ref T obj)
    {
        return (T)obj;
    }

    // This version would, however, work just fine
    private static T ConvertToType2<T>(ref T obj) where T : IConvertible
    {
        return (T) Convert.ChangeType(obj, typeof(T));
    }
}

}

use this

  by  vinothkumar, 2 months ago




Please log in to post a comment.