mirror of
https://github.com/Smaug123/WoofWare.PawPrint
synced 2025-10-13 17:48:39 +00:00
Implement Castclass
This commit is contained in:
31
WoofWare.PawPrint.Test/sourcesPure/CastClassInvalid.cs
Normal file
31
WoofWare.PawPrint.Test/sourcesPure/CastClassInvalid.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
public class Program
|
||||
{
|
||||
public class Cat
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
public class Dog
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
object cat = new Cat { Name = "Whiskers" };
|
||||
|
||||
// Invalid cast - should throw InvalidCastException
|
||||
Dog dog = (Dog)cat;
|
||||
|
||||
// Should not reach here
|
||||
return 0;
|
||||
}
|
||||
catch (System.InvalidCastException)
|
||||
{
|
||||
// Expected exception caught
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user