Use interface as a parameter : Class as Parameter « Class « C# / CSharp Tutorial






interface Animal
{
}

class Dog : Animal
{
}

class Cat : Animal
{
}

class MainClass
{
   static void ListenToMe( Animal listener )
   {
   }
   
   static void Main()
   {
      Dog dog = new Dog();
      Cat cat = new Cat();

      ListenToMe( dog );
      ListenToMe( cat );
   }
}








7.31.Class as Parameter
7.31.1.Passing ref-types by ref
7.31.2.Use interface as a parameter