C# program to demonstrate InvalidCastException exception
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Program:
The source code to demonstrate the InvalidCastException exception is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created a class ExceptionDemo that contains the Main() method. In the Main() method, we created a variable intNum and object Ob.
In the above code, we type-caste object Ob into integer but we used the short keyword for typecasting then InvalidCastException gets generated that will be caught in the "catch" block and then print the exception message using the "Message" property on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer