次のコードで、明示的インターフェイス実装構文を使用して 'CalcUsable' を定義する必要があるのはなぜですか? (コードの最後の行を参照してください) 非明示的な構文 (つまり public decimal CalcUsable) を使用すると、「一貫性のないアクセシビリティ」エラーが発生します。具体的には:
「パラメータ型 ...List (IVoucher) はメソッド CalcUsable(...) よりアクセスしにくい」
interface IVoucher
{
string Serial { get; }
decimal FaceValue { get; }
string DiscountType { get; }
string ApplyMsg { get; }
string RejectMsg { get; }
decimal CalcUsable(List<Product> products, List<IVoucher> vouchers);
}
// 'GiftVoucher' models the simple voucher which has no use restrictions.
//
public class GiftVoucher : IVoucher
{
public string Serial { get; private set; }
public decimal FaceValue { get; private set; }
public string DiscountType { get; private set; }
public string ApplyMsg { get; private set; }
public string RejectMsg { get; private set; }
public GiftVoucher(string serial, decimal faceValue)
{
Serial = serial;
FaceValue = faceValue;
ApplyMsg = string.Empty;
RejectMsg = string.Empty;
DiscountType = "Gift";
}
// 'CalcUsable' provides the voucher applicability logic.
//
decimal IVoucher.CalcUsable(List<Product> products, List<IVoucher> vouchers)
{
blar, blar, blar...