InvalidCastException Exception : Buildin Exceptions : Development Class C# Source Code


Custom Search

C# Source Code » Development Class » Buildin Exceptions »

 

InvalidCastException Exception








    

using System;
   
class MainClass
{
    public static void Main()
    {
        try
        {
            MainClass       MyObject = new MainClass();
            IFormattable    Formattable;
   
            Formattable = (IFormattable)MyObject;
   
            // wait for user to acknowledge the results
            Console.WriteLine("Hit Enter to terminate...");
            Console.Read();
        }
        catch(InvalidCastException)
        {
            Console.WriteLine("MyObject does not implement the IFormattable interface.");
        }
    }
}
           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Development Class
» Buildin Exceptions