0
我有以下類解決方法爲通用的回報
public abstract class Rule { protected Rule() { Nodes = new List<Node>(); } public List<Node> Nodes { get; private set; } public int NumberOfElements { get; set; } public abstract Result<Rule> Validate(IEnumerable<Node> validUnits); }
現在,我也有:
public class MinNumberOfCredits : Rule { public override string ToString() { return string.Format(NumberOfElements); } public override Result<Rule> Validate(IEnumerable<Node> validUnits) { var totalCredits = validUnits.Sum(x => x.Credits); return NumberOfElements > totalCredits ? new Result<MinNumberOfCredits>(ResultMessage.Fail, NumberOfElements) : new Result<MinNumberOfCredits>(); } }
的問題是,我的返回類型爲Result<Rule>
但在具體的班級我必須返回Result<MinNumberOfCredits>
。
爲什麼你需要返回Result? –
2012-01-02 10:32:05
爲什麼你不能將返回類型改爲'Result'? –
dotNETbeginner
2012-01-02 11:17:40
因爲結果和結果是不同的東西,所以在基類中我只有基本規則。 –
user872761
2012-01-02 12:17:19