mirror of
https://github.com/github/codeql.git
synced 2026-07-11 14:35:31 +02:00
21 lines
496 B
C#
21 lines
496 B
C#
class ChainedIs
|
|
{
|
|
interface Animal { }
|
|
class Cat : Animal { }
|
|
class Dog : Animal { }
|
|
|
|
public static void Main(string[] args)
|
|
{
|
|
List<Animal> animals = new List<Animal> { new Cat(), new Dog() };
|
|
foreach (Animal a in animals)
|
|
{
|
|
if (a is Cat)
|
|
Console.WriteLine("Miaow!");
|
|
else if (a is Dog)
|
|
Console.WriteLine("Woof!");
|
|
else
|
|
throw new Exception("Oops!");
|
|
}
|
|
}
|
|
}
|