问题描述
嗨;
我正在编写一个实现IDbConnection的类。 i / f定义了一个方法
BeginTransaction()返回一个IDbTransaction。我想将此定义为
返回DbTransaction(如DbConnection所做)。这对我来说很有意义
这是合法的,因为DbTransaction实现了IDbTransaction,所以它确实符合返回IDbTransaction的
合约。
但它不会编译 - 我如何让它工作?必须有一种方式,因为
DbConnection这样做。
我尝试过显式/隐式但是收到一条错误消息说只能是
与运营商一起使用。
-
谢谢 - 戴夫
david_at_windward_dot_net
Hi;
I am writing a class that implements IDbConnection. The i/f defines a method
BeginTransaction() that returns an IDbTransaction. I want to define this as
returning a DbTransaction (as DbConnection does). It makes sense to me that
this is legal as DbTransaction implements IDbTransaction so it does meet the
contract of returning an IDbTransaction.
But it won''t compile - how do I get this to work? There must be a way as
DbConnection does it.
I tried explicit/implicit but got an error message saying that could only be
used with operators.
--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com
推荐答案
这篇关于再问:实现接口,返回子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!