C#以泛型方法返回Dictionary

时间:2013-04-25 12:50:09

标签: c# generics dictionary return return-value

public abstract BaseClass
 {
    public abstract Dictionary<T, V> ExtractSummaryInfo<T, V>()
        where V : Product;    
 }

public MyClass : BaseClass
 {
   public override Dictionary<T, V> ExtractSummaryInfo<T, V>()
      {
        Dictionary<T, V> products = new Dictionary<T, V>();

        string id = "HRM";
        Product product = new Product("Product 1");

        products[id as T] = product as V;

        return products;
       }
  }

在我看来,这行代码(产品[id为T] =产品为V;)是错误的,请告诉我如何实现这种方法?

0 个答案:

没有答案