InvalidCastException
: Casting Conversions « Data Types « C# / C Sharp
- C# / C Sharp
- Data Types
- Casting Conversions
InvalidCastException
using System;
class MainClass
{
public static void Main()
{
try
{
MainClass MyObject = new MainClass();
IFormattable Formattable;
Formattable = (IFormattable)MyObject;
}
catch(InvalidCastException)
{
Console.WriteLine("MyObject does not implement the IFormattable interface.");
}
}
}
Related examples in the same category