mercredi 4 octobre 2017

Allowing an Interface to return a Class in C#

Is there a way for an interface to return voids as well as classes?

Interface

public interface IAnimalSlide<C> where <C>:ImageViewer
{
  void endShow();
  imageViewer displayImage();
  void setNewImage();
}

CatSlide

public class Cat: IAnimalShow
...

public System.Windows.Controls.ImageViewer displayImage(){
     return displaySingeImage();
}

ImageSlideShow

public class SlideShow 
{
   IAnimalSlide = prevSlide;
   IAnimalSlide = nextSlide;
   List<IAnimalSlide> animalList;
}   

... 
animalList.catList.ToList<IAnimalSlide>(); //where catList is a list of Cats
Canvas.showImage(IAnimalSlide.displayImage());

I'm currently getting an error that says

Using a generic type 'IAnimalSlide' requires 1 type of arguments

The ImageSlideShow calls a class called ImageViewer and I want to call that in the interface. Is there a way I can incorporate that class within the interface?

Aucun commentaire:

Enregistrer un commentaire