Files
WoofWare.PawPrint/WoofWare.PawPrint.Test/sourcesPure/IsinstFailedInterface.cs
Smaug123 277f303431 WIP
2025-06-27 12:09:15 +01:00

31 lines
679 B
C#

public class Program
{
public interface IAnimal
{
string Name { get; set; }
}
public class Bird : IAnimal
{
public string Name { get; set; }
public bool CanFly { get; set; }
}
public class Fish : IAnimal
{
public string Name { get; set; }
public bool CanSwim { get; set; }
}
public static int Main(string[] args)
{
IAnimal animal = new Bird { Name = "Sparrow", CanFly = true };
// This should fail at runtime and return null (not throw)
// because the actual object is Bird, not Fish
Fish fish = animal as Fish;
return fish == null ? 42 : 0;
}
}