如何在<T> wp8 中返回列表



我试图使用下面的代码返回<T>,但似乎我做错了什么。

public class Chapter
{
   public Byte ChapterID { get; set; }
   public string SuraName { get; set; }
}
public class Recent
{
   public Byte RecentID{get;set;}
   public string Description{get;set;}
}
public class ChapterMenusHeader : INotifyPropertyChanged
{
List<T> _myList;
public List<T> MyList
{
   get { return _myList;}
   set {_myList = value;}
}
}

其中<T>可以是任何通用类型

我得到以下编译错误

The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)

我怎么能有下面的?

List<Chapter> chapters = new ChapterMenusHeader().MyList;
List<Recent> myRecent = new ChapterMenusHeader().MyList;

谢谢!

这是的解决方案

具有泛型类型的C#属性和为什么C#中没有泛型属性?

试试这个:

public class ChapterMenusHeader<T> : INotifyPropertyChanged
{
List<T> _myList;
public List<T> MyList
{
   get { return _myList;}
   set {_myList = value;}
}
}

然后这个:

List<Chapter> chapters = new ChapterMenusHeader<Chapter>().MyList;

最新更新