mirror of
https://github.com/Smaug123/WoofWare.PawPrint
synced 2025-10-17 11:28:39 +00:00
WIP
This commit is contained in:
@@ -14,8 +14,11 @@ public class Program
|
||||
{
|
||||
Bird sparrow = new Bird { CanFly = true };
|
||||
|
||||
// This should fail and return null (not throw)
|
||||
Fish fish = sparrow as Fish;
|
||||
// Cast to object first to bypass compile-time checking
|
||||
object obj = sparrow;
|
||||
|
||||
// This should fail at runtime and return null (not throw)
|
||||
Fish fish = obj as Fish;
|
||||
|
||||
return fish == null ? 42 : 0;
|
||||
}
|
||||
|
30
WoofWare.PawPrint.Test/sourcesPure/IsinstFailedInterface.cs
Normal file
30
WoofWare.PawPrint.Test/sourcesPure/IsinstFailedInterface.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user