我对泛型对象有些怀疑,不知道我的想法是否可以轻松实现......
我有实现相同接口的对象,因此除了主要对象之外,方法几乎相等,如下面的代码:
public bool Func1 (Bitmap img)
{
   Obj1                 treatments    = new Obj1 ();
   List<UnmanagedImage> unmanagedList = treatments.ExtractLetters(img);
   // Check image treatments
   if (!treatments.WasSuccessful)
      return false
   return true
}
public bool Func2 (Bitmap img)
{
   Obj2                 treatments    = new Obj2 ();
   List<UnmanagedImage> unmanagedList = treatments.ExtractLetters(img);
   // Check image treatments
   if (!treatments.WasSuccessful)
      return false
   return true
}
在这种情况下,我不想复制代码。有什么简单的方法可以使这个 Obj1 和 Obj2 通用吗?因为我只能编写一个函数,然后该函数可以在对象中进行强制转换,因为其余的都是一样的。
谢谢!